You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Piccolo ORM has a feature for scaffolding simple ASGI applications for various ASGI frameworks. I notice that Swagger and Redoc docs do not work with the latest version of Litestar. The latest working version is Litestar==2.11.0.
For scaffolding ASGI apps, we don't use PiccoloDTO but Piccolo's internal tool (create_pydantic_model) to create a Pydantic model from a Piccolo table, which has an extra property, but Litestar Schema does not has a extra key and that causes a ValueError to be raised. I tried two things and after that everything works.
or excluding the extra key from checking here like this.
ifnothasattr(schema, schema_key) andschema_key!="extra":
raiseValueError(
f"`schema_extra` declares key `{schema_key}` which does not exist in `Schema` object"
)
I don't know if that's good enough, but these are just ideas. Any solution that will enable Piccolo ORM works with the latest Litestar version will be great. Thanks in advance.
URL to code causing the issue
No response
MCVE
https://github.com/sinisaos/simple-piccolo
Steps to reproduce
1. Clone repository
2. Install requirements
3. Start app with `python litestar_app.py`
4. Go to `http://localhost:8000/schema/swagger` and see error
Screenshots
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Logs
ERROR - 2024-09-28 07:35:34,331 - litestar - config - Uncaught exception (connection_type=http, path=/schema/swagger):
Traceback (most recent call last):
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/middleware/_internal/exceptions/middleware.py", line 159, in __call__
await self.app(scope, receive, capture_response_started)
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_asgi/asgi_router.py", line 100, in __call__
await asgi_app(scope, receive, send)
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/routes/http.py", line 80, in handle
response = await self._get_response_for_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/routes/http.py", line 132, in _get_response_for_request
return await self._call_handler_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/routes/http.py", line 152, in _call_handler_function
response_data, cleanup_group = await self._get_response_data(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/routes/http.py", line 195, in _get_response_data
data = route_handler.fn(**parsed_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/plugin.py", line 161, in _handler
return plugin_.render(request, self.provide_openapi_schema())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/plugin.py", line 99, in provide_openapi_schema
self._openapi_schema = self.provide_openapi().to_schema()
^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/plugin.py", line 94, in provide_openapi
self._openapi = self._build_openapi()
^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/plugin.py", line 83, in _build_openapi
path_item = create_path_item_for_route(context, route)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/path_item.py", line 139, in create_path_item_for_route
returnpath_item_factory.create_path_item()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/path_item.py", line 44, in create_path_item
operation = self.create_operation_for_handler_method(route_handler, HttpMethod(http_method))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/path_item.py", line 68, in create_operation_for_handler_method
request_body = create_request_body(
^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/request_body.py", line 49, in create_request_body
schema = schema_creator.for_field_definition(data_field)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/schema_generation/schema.py", line 333, in for_field_definition
result = self.for_plugin(field_definition, plugin_for_annotation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/schema_generation/schema.py", line 515, in for_plugin
schema = plugin.to_openapi_schema(field_definition=field_definition, schema_creator=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/contrib/pydantic/pydantic_schema_plugin.py", line 235, in to_openapi_schema
return self.for_pydantic_model(field_definition=field_definition, schema_creator=schema_creator)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/contrib/pydantic/pydantic_schema_plugin.py", line 252, in for_pydantic_model
return schema_creator.create_component_schema(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/schema_generation/schema.py", line 645, in create_component_schema
schema.properties = {k: self.for_field_definition(v) fork, vinproperty_fields.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/schema_generation/schema.py", line 645, in<dictcomp>
schema.properties = {k: self.for_field_definition(v) fork, vinproperty_fields.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/schema_generation/schema.py", line 361, in for_field_definition
return self.process_schema_result(field_definition, result) if isinstance(result, Schema) else result
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rkl/dev/piccolo_env/lib/python3.11/site-packages/litestar/_openapi/schema_generation/schema.py", line 596, in process_schema_result
raise ValueError(
ValueError: `schema_extra` declares key `extra` which does not exist in`Schema` object
This is a bug on Piccolo's side. Litestar is strict about the OpenAPI schema, which does not specify an extra property field as of version 3.1, nor does it allow arbitrary fields, but Piccolo seems to use this to include additional information.
Description
Piccolo ORM has a feature for scaffolding simple ASGI applications for various ASGI frameworks. I notice that
Swagger
andRedoc
docs do not work with the latest version of Litestar. The latest working version isLitestar==2.11.0
.For scaffolding ASGI apps, we don't use
PiccoloDTO
but Piccolo's internal tool (create_pydantic_model) to create a Pydantic model from a Piccolo table, which has anextra
property, but Litestar Schema does not has aextra
key and that causes aValueError
to be raised. I tried two things and after that everything works.extra
key to a Schema like thisextra
key from checking here like this.I don't know if that's good enough, but these are just ideas. Any solution that will enable Piccolo ORM works with the latest Litestar version will be great. Thanks in advance.
URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Logs
Litestar Version
2.12.1
Platform
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: