internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ckan/ckan

Issue:
Custom Data Dictionary preview
## CKAN version
master

## Describe the bug
IDataDictionaryForm lets us expand on the data dictionary form and validation but not the Data Dictionary preview in the resource pages

### Steps to reproduce
Use IDataDictionaryForm to add fields to the data dictionary.

### Expected behavior
New fields should be visible in the resource page, not only the DataStore types, labels and descriptions

### Additional details


Discussion:

Resolving patch:
diff --git a/ckanext/datastore/backend/postgres.py b/ckanext/datastore/backend/postgres.py
--- a/ckanext/datastore/backend/postgres.py
+++ b/ckanext/datastore/backend/postgres.py
@@ -2315,7 +2315,12 @@ def resource_fields(self, id: str) -> dict[str, Any]:
             info['meta']['aliases'] = aliases
 
             # get the data dictionary for the resource
-            data_dictionary = datastore_helpers.datastore_dictionary(id)
+            with engine.connect() as conn:
+                data_dictionary = _result_fields(
+                    _get_fields_types(conn, id),
+                    _get_field_info(conn, id),
+                    None
+                )
 
             schema_sql = sa.text(f'''
                 SELECT
@@ -2361,6 +2366,8 @@ def resource_fields(self, id: str) -> dict[str, Any]:
                 schemainfo[colname] = colinfo
 
             for field in data_dictionary:
+                if field['id'].startswith('_'):
+                    continue
                 field.update({'schema': schemainfo[field['id']]})
                 info['fields'].append(field)
 
diff --git a/ckanext/datastore/helpers.py b/ckanext/datastore/helpers.py
--- a/ckanext/datastore/helpers.py
+++ b/ckanext/datastore/helpers.py
@@ -216,11 +216,8 @@ def datastore_dictionary(
     """
     try:
         return [
-            f for f in tk.get_action('datastore_search')(
-                {}, {
-                    u'resource_id': resource_id,
-                    u'limit': 0,
-                    u'include_total': False})['fields']
+            f for f in tk.get_action('datastore_info')(
+                {}, {'id': resource_id})['fields']
             if not f['id'].startswith(u'_') and (
                 include_columns is None or f['id'] in include_columns)
             ]


Test patch:
Repository: ckan/ckan

Issue:
package_patch breaks uploaded resources
## CKAN version
2.10.4

## Describe the bug
When using package_patch to update a dataset, intending **not** to update an uploaded resource the resource filename appears to be lost

### Steps to reproduce
1. Create a dataset containing at least one uploaded file resource
2. Call package_patch to update the dataset, but for the resources only pass the resource ids like specified in the documentation 
(https://docs.ckan.org/en/2.10/api/#ckan.logic.action.patch.package_patch) like:
```
package_patch(**{'id':'b6cc8622-3334-4cdb-8960-e2a3c4269a8d', 
                 'description':'Updated description', 
                 'resources':[{'id':'a97b8889-5efb-440c-b6ad-fa9a9e4d7659'},
                              {'id':'bdbb977f-9faa-4715-88d3-c5e9042e69a4', 
                               'description':'Updated resource description'}]})
```
3. Browse to the updated resource, the download link is missing the file name probably replaced by ___ and the mimetype is lost


### Expected behavior
The resources should be unchanged when no changes are requested

### Additional details
I think part of this issue arises out of url being used to store the filename. It may be cleaner to just add filename as another field in uploaded resources which could also make renaming uploaded files easier.



Discussion:
Thanks @pdekraker-epa the `package_patch` docs added by https://github.com/ckan/ckan/pull/4563 are incorrect. I'll create a PR to remove them.

`package_patch` has no understanding of the package/resource structure and instead simply replaces any keys passed (including `resources`) through to `package_update`.

If you want to update some fields at the dataset level and other fields at the resource level you can use `package_revise` instead which lets you replace specific fields at any level of nesting without disturbing other existing fields.

Resolving patch:
diff --git a/ckan/logic/action/patch.py b/ckan/logic/action/patch.py
--- a/ckan/logic/action/patch.py
+++ b/ckan/logic/action/patch.py
@@ -24,12 +24,10 @@ def package_patch(
     parameters unchanged, whereas the update methods deletes all parameters
     not explicitly provided in the data_dict.
 
-    You are able to partially update and/or create resources with
-    package_patch. If you are updating existing resources be sure to provide
-    the resource id. Existing resources excluded from the package_patch
-    data_dict will be removed. Resources in the package data_dict without
-    an id will be treated as new resources and will be added. New resources
-    added with the patch method do not create the default views.
+    To partially update resources or other metadata not at the top level
+    of a package use
+    :py:func:`~ckan.logic.action.update.package_revise` instead to maintain
+    existing nested values.
 
     You must be authorized to edit the dataset and the groups that it belongs
     to.


Test patch:
Repository: ckan/ckan

Issue:
missing ckan db create-from-model
## CKAN version
master, 2.10, 2.9

## Describe the bug
Documented `ckan db create-from-model` command https://docs.ckan.org/en/2.10/contributing/database-migrations.html#manual-checking doesn't exist.

### Steps to reproduce
Follow steps in database migrations document

### Expected behavior

### Additional details
Seems to have been removed in migration to click cli


Discussion:

Resolving patch:
diff --git a/ckan/cli/db.py b/ckan/cli/db.py
--- a/ckan/cli/db.py
+++ b/ckan/cli/db.py
@@ -41,6 +41,18 @@ def init():
         click.secho(u'Initialising DB: SUCCESS', fg=u'green', bold=True)
 
 
+@db.command()
+def create_from_model():
+    """Initialize database from the model instead of migrations.
+    """
+    try:
+        model.repo.create_db()
+    except Exception as e:
+        error_shout(e)
+    else:
+        click.secho('Create DB from model: SUCCESS', fg='green', bold=True)
+
+
 PROMPT_MSG = u'This will delete all of your data!\nDo you want to continue?'
 
 


Test patch:
Repository: litestar-org/litestar

Issue:
ResponseHeader throws `object has no attribute 'encode'` error
**Describe the bug**
When I try to set headers:
``` python
 @post(tags=["search"],response_headers = {
        "testheader": ResponseHeader(value="test value",description="test")
    })
```
I get:
```python
AttributeError("'ResponseHeader' object has no attribute 'encode'")
```
**To Reproduce**
[this repo](https://github.com/denizkenan/starlite-hello-world) has mentioned bug




Discussion:

Resolving patch:
diff --git a/starlite/handlers/http.py b/starlite/handlers/http.py
--- a/starlite/handlers/http.py
+++ b/starlite/handlers/http.py
@@ -187,10 +187,11 @@ def _create_data_handler(
     async def handler(data: Any, plugins: List["PluginProtocol"], **kwargs: Any) -> StarletteResponse:
         data = await _normalize_response_data(data=data, plugins=plugins)
         normalized_cookies = _normalize_cookies(cookies, [])
+        normalized_headers = _normalize_headers(headers)
         response = response_class(
             background=background,
             content=data,
-            headers=headers,
+            headers=normalized_headers,
             media_type=media_type,
             status_code=status_code,
         )


Test patch:
diff --git a/tests/response/test_response_headers.py b/tests/response/test_response_headers.py
--- a/tests/response/test_response_headers.py
+++ b/tests/response/test_response_headers.py
@@ -1,7 +1,11 @@
+from typing import Dict
+
 import pytest
 from pydantic import ValidationError
+from starlette.status import HTTP_201_CREATED
 
-from starlite import Controller, HttpMethod, ResponseHeader, Router, Starlite, get
+from starlite import Controller, HttpMethod, ResponseHeader, Router, Starlite, get, post
+from starlite.testing import create_test_client
 
 
 def test_response_headers() -> None:
@@ -53,3 +57,18 @@ def test_response_headers_validation() -> None:
     ResponseHeader(documentation_only=True)
     with pytest.raises(ValidationError):
         ResponseHeader()
+
+
+def test_response_headers_rendering() -> None:
+    @post(
+        path="/test",
+        tags=["search"],
+        response_headers={"test-header": ResponseHeader(value="test value", description="test")},
+    )
+    def my_handler(data: Dict[str, str]) -> Dict[str, str]:
+        return data
+
+    with create_test_client(my_handler) as client:
+        response = client.post("/test", json={"hello": "world"})
+        assert response.status_code == HTTP_201_CREATED
+        assert response.headers.get("test-header") == "test value"
Repository: litestar-org/litestar

Issue:
Bug: logging queue listener writing to in-memory stream
The handler for the `queue_listener` handler is created as `StreamHandler(StringIO())`. Explicitly passing the stream to the the handler means that the output is no longer logged to stderr.



Discussion:

Resolving patch:
diff --git a/starlite/config/logging.py b/starlite/config/logging.py
--- a/starlite/config/logging.py
+++ b/starlite/config/logging.py
@@ -132,7 +132,7 @@ class LoggingConfig(BaseLoggingConfig, BaseModel):
     }
     """A dict in which each key is a logger name and each value is a dict describing how to configure the corresponding Logger instance."""
     root: Dict[str, Union[Dict[str, Any], List[Any], str]] = {
-        "handlers": ["queue_listener", "console"],
+        "handlers": ["queue_listener"],
         "level": "INFO",
     }
     """This will be the configuration for the root logger. Processing of the configuration will be as for any logger,
diff --git a/starlite/logging/picologging.py b/starlite/logging/picologging.py
--- a/starlite/logging/picologging.py
+++ b/starlite/logging/picologging.py
@@ -1,5 +1,4 @@
 import atexit
-from io import StringIO
 from logging import StreamHandler
 from queue import Queue
 from typing import Any, List, Optional
@@ -28,7 +27,7 @@ def __init__(self, handlers: Optional[List[Any]] = None) -> None:
         if handlers:
             handlers = resolve_handlers(handlers)
         else:
-            handlers = [StreamHandler(StringIO())]
+            handlers = [StreamHandler()]
         self.listener = QueueListener(self.queue, *handlers)
         self.listener.start()
 
diff --git a/starlite/logging/standard.py b/starlite/logging/standard.py
--- a/starlite/logging/standard.py
+++ b/starlite/logging/standard.py
@@ -1,5 +1,4 @@
 import atexit
-from io import StringIO
 from logging import StreamHandler
 from logging.handlers import QueueHandler, QueueListener
 from queue import Queue
@@ -20,7 +19,7 @@ def __init__(self, handlers: Optional[List[Any]] = None) -> None:
         if handlers:
             handlers = resolve_handlers(handlers)
         else:
-            handlers = [StreamHandler(StringIO())]
+            handlers = [StreamHandler()]
         self.listener = QueueListener(self.queue, *handlers)
         self.listener.start()
 


Test patch:
Repository: litestar-org/litestar

Issue:
Bug: Picologging not behaving correctly 
**Describe the bug**
i reported an earlier issue to @peterschutt about logging configuration not visible in the console output.
that was fixed in https://github.com/starlite-api/starlite/pull/594

i now wanted to test this out with picologging but it seems to override the LoggingConfig settings.

**To Reproduce**
checkout https://github.com/starlite-api/starlite-pg-redis-docker    and add picologging to the application.
then you see the behaviour i describe here.

nothing else changes so only add picologging.

**Additional context**
you can see the behaviour already at starting the project with docker-compose up.

without picologging in project:

app_1      | Starting Starlite App...
app_1      | INFO:     Will watch for changes in these directories: ['/app']
app_1      | INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
app_1      | INFO:     Started reloader process [10] using WatchFiles
app_1      | INFO:     Started server process [12]
app_1      | INFO:     Waiting for application startup.
app_1      | 2022-10-16 18:38:14,888 loglevel=INFO   logger=uvicorn.error serve() L75   Started server process [12]
app_1      | 2022-10-16 18:38:14,888 loglevel=INFO   logger=uvicorn.error startup() L47   Waiting for application startup.
app_1      | INFO:     Application startup complete.
app_1      | 2022-10-16 18:38:14,908 loglevel=INFO   logger=uvicorn.error startup() L61   Application startup complete.

with picologging in project:

app_1      | Starting Starlite App...
app_1      | INFO:     Will watch for changes in these directories: ['/app']
app_1      | INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
app_1      | INFO:     Started reloader process [10] using WatchFiles
app_1      | INFO:     Started server process [12]
app_1      | INFO:     Waiting for application startup.
app_1      | INFO:     Application startup complete.


i tried looking at the documentation of picologging https://microsoft.github.io/picologging/handlers.html   section Queue Listener but it seems to be correct. at this point im lacking knowledge in the logging department to troubleshoot this deeper.

Kind regards,
Niels



Discussion:

Resolving patch:
diff --git a/starlite/logging/picologging.py b/starlite/logging/picologging.py
--- a/starlite/logging/picologging.py
+++ b/starlite/logging/picologging.py
@@ -1,5 +1,4 @@
 import atexit
-from logging import StreamHandler
 from queue import Queue
 from typing import Any, List, Optional
 
@@ -7,6 +6,7 @@
 from starlite.logging.utils import resolve_handlers
 
 try:
+    from picologging import StreamHandler
     from picologging.handlers import QueueHandler, QueueListener
 except ImportError as e:
     raise MissingDependencyException("picologging is not installed") from e


Test patch:
Repository: litestar-org/litestar

Issue:
Bug: "method" not extracted response field
https://github.com/starlite-api/starlite/blob/34740bd61493b970fe52005c4922a9f4a3a7d83c/starlite/utils/extractors.py#L48



Discussion:

Resolving patch:
diff --git a/starlite/middleware/logging.py b/starlite/middleware/logging.py
--- a/starlite/middleware/logging.py
+++ b/starlite/middleware/logging.py
@@ -176,6 +176,7 @@ def extract_response_data(self, scope: "Scope") -> Dict[str, Any]:
             )
         )
         for key in self.config.response_log_fields:
+            value: Any
             value = extracted_data.get(key)
             if not self.is_struct_logger and isinstance(value, (dict, list, tuple, set)):
                 value = dumps(value, default=serializer, option=OPT_SERIALIZE_NUMPY | OPT_OMIT_MICROSECONDS)
diff --git a/starlite/utils/extractors.py b/starlite/utils/extractors.py
--- a/starlite/utils/extractors.py
+++ b/starlite/utils/extractors.py
@@ -45,7 +45,7 @@ def obfuscate(values: Dict[str, Any], fields_to_obfuscate: Set[str]) -> Dict[str
     "path", "method", "content_type", "headers", "cookies", "query", "path_params", "body", "scheme", "client"
 ]
 
-ResponseExtractorField = Literal["status_code", "method", "headers", "body", "cookies"]
+ResponseExtractorField = Literal["status_code", "headers", "body", "cookies"]
 
 
 class ExtractedRequestData(TypedDict, total=False):


Test patch:
Repository: litestar-org/litestar

Issue:
SQLAlchemy Session backend uses wrong column type in `SessionModelMixin`
**Describe the bug**
The SQLAlchem session backend uses `BLOB` as the datatype in the `SessionModelMixin`, which is not compatible with all databases. 




Discussion:

Resolving patch:
diff --git a/starlite/middleware/session/sqlalchemy_backend.py b/starlite/middleware/session/sqlalchemy_backend.py
--- a/starlite/middleware/session/sqlalchemy_backend.py
+++ b/starlite/middleware/session/sqlalchemy_backend.py
@@ -31,7 +31,7 @@ class SessionModelMixin:
     """Mixin for session storage."""
 
     session_id: Mapped[str] = sa.Column(sa.String, nullable=False, unique=True, index=True)  # pyright: ignore
-    data: Mapped[bytes] = sa.Column(sa.BLOB, nullable=False)  # pyright: ignore
+    data: Mapped[bytes] = sa.Column(sa.LargeBinary, nullable=False)  # pyright: ignore
     expires: Mapped[datetime] = sa.Column(sa.DateTime, nullable=False)  # pyright: ignore
 
     @hybrid_property


Test patch:
Repository: litestar-org/litestar

Issue:
Bug: Structlog example throws a 500 error
**Describe the bug**
Using the [Structlog sample code](https://starlite-api.github.io/starlite/usage/0-the-starlite-app/4-logging) with Starlite returns a 500 error.

**To Reproduce**
Paste the exact sample code linked into a text file, run.py.
Have the dependencies (below) installed and available.
Run the command `uvicorn run:app`.
Hit http://localhost:8000 in the browser.
Error response: `{"status_code":500,"detail":"TypeError(\"_make_filtering_bound_logger.<locals>.log() missing 1 required positional argument: 'event'\")"}`

**Additional context**
Python 3.10
Starlite 1.39.0
Structlog 22.3.0
Uvicorn 0.19.0 (extras = standard)
MacOS Monterey 12.16.1




Discussion:
~~@robertlagrant could you please try to launch the code with the latest Starlite version.~~

nvm, I wasn't paying attention to the error message. 
@jtraub same on Starlite 1.42.0 anyway :)
@robertlagrant it is just a typo in the docs.

Loggers follow [`Logger`](https://github.com/starlite-api/starlite/blob/main/starlite/types/protocols.py#L4) protocol which doesn't have `log` method. So you need to replace
```python
request.logger.log("inside a request")
```
in the example code with
```python
request.logger.info("inside a request")
```

and it should work.
There is an ongoing effort to make sure that all examples in the docs are runnable (#343).

@provinzkraut is working hard on this and I think it will be addressed soon.
Confirmed - this change works.
```bash
% poetry run uvicorn run:app
INFO:     Started server process [80291]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
{"event":"inside a request","level":"info","timestamp":"2022-11-28T19:19:25.317728Z"}
INFO:     127.0.0.1:62892 - "GET / HTTP/1.1" 200 OK
```

Resolving patch:
diff --git a/starlite/middleware/session/memcached_backend.py b/starlite/middleware/session/memcached_backend.py
--- a/starlite/middleware/session/memcached_backend.py
+++ b/starlite/middleware/session/memcached_backend.py
@@ -63,7 +63,8 @@ async def delete(self, session_id: str) -> None:
         await self.memcached.delete(self._id_to_storage_key(session_id))
 
     @deprecated(
-        "1.43.0", info="This functionality is not natively supported by memcached. Use the redis backend instead if you require it."
+        "1.43.0",
+        info="This functionality is not natively supported by memcached. Use the redis backend instead if you require it.",
     )
     async def delete_all(self) -> None:  # pragma: no cover
         """Delete all data stored within this backend.


Test patch:
Repository: litestar-org/litestar

Issue:
Bug: Viewing default schema then swagger schema results in error
**Describe the bug**
Viewing the standard `/schema` route and then viewing `/schema/swagger` results in an empty page. The console log on the swagger route mentions parsing invalid JSON (Trying to parse nothing - `JSON.parse()`)

I believe the problem is the caching located [here](https://github.com/starlite-api/starlite/blob/55eea965b2ac9e56aca77797512ab878b0b7499b/starlite/openapi/controller.py#L306). It should be checking for `self._dumped_modified_schema`. Changing to this seems to fix it.

**To Reproduce**
Run the hello world example from the documentation:
```python

from typing import Dict

from starlite import Starlite, get


@get("/")
def hello_world() -> Dict[str, str]:
    """Handler function that returns a greeting dictionary."""
    return {"hello": "world"}


app = Starlite(route_handlers=[hello_world])
```
Then visit `/schema` and the page should be fine. Then visit `/schema/swagger` and it should be an empty page.

**Additional context**
Add any other context about the problem here.



Discussion:

Resolving patch:
diff --git a/starlite/openapi/controller.py b/starlite/openapi/controller.py
--- a/starlite/openapi/controller.py
+++ b/starlite/openapi/controller.py
@@ -303,7 +303,7 @@ def render_swagger_ui(self, request: Request) -> str:
         """
         schema = self.get_schema_from_request(request)
         # Note: Fix for Swagger rejection OpenAPI >=3.1
-        if not self._dumped_schema:
+        if not self._dumped_modified_schema:
             schema_copy = schema.copy()
             schema_copy.openapi = "3.0.3"
 


Test patch:
diff --git a/tests/openapi/test_controller.py b/tests/openapi/test_controller.py
--- a/tests/openapi/test_controller.py
+++ b/tests/openapi/test_controller.py
@@ -153,6 +153,21 @@ def test_openapi_swagger(root_path: str) -> None:
         assert response.headers["content-type"].startswith(MediaType.HTML.value)
 
 
+@pytest.mark.parametrize("root_path", root_paths)
+def test_openapi_swagger_caching_schema(root_path: str) -> None:
+    with create_test_client(
+        [PersonController, PetController], openapi_config=DEFAULT_OPENAPI_CONFIG, root_path=root_path
+    ) as client:
+        # Make sure that the schema is tweaked for swagger as the openapi version is changed.
+        # Because schema can get cached, make sure that getting a different schema type before works.
+        client.get("/schema/redoc")  # Cache the schema
+        response = client.get("/schema/swagger")  # Request swagger, should use a different cache
+
+        assert "3.0.3" in response.text  # Make sure the injected version is still there
+        assert response.status_code == HTTP_200_OK
+        assert response.headers["content-type"].startswith(MediaType.HTML.value)
+
+
 @pytest.mark.parametrize("root_path", root_paths)
 def test_openapi_stoplight_elements(root_path: str) -> None:
     with create_test_client(