SQLAdminPlugins works on its own but breaks when StructlogPlugin is added. I believe this is a Litestar Internal bug however which is why I'm raising this issue here. I have determined that:
litestar/data_extractors.py:172
calls self.extract_body()
calls request.form()
calls self.stream()
calls self.route_handler.resolve_request_max_body_size()
self.route_handler
is NOT HTTPRouteHandler
as expected, but instead ASGIRouteHandler
, which does not support this method. except Exception as exc:
if self.skip_parse_malformed_body:
return await request.body() <--- again ends up calling Request.stream(), raising same exception.
raise exc
No response
from litestar import Litestar
from sqladmin import ModelView
from sqladmin_litestar_plugin import SQLAdminPlugin
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import declarative_base
from litestar.plugins.structlog import StructlogConfig, StructlogPlugin
engine = create_async_engine("sqlite+aiosqlite:///example.db")
Base = declarative_base()
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
name = Column(String)
class UserAdmin(ModelView, model=User):
column_list = [User.id, User.name]
async def on_startup() -> None:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all) # Create tables
admin = SQLAdminPlugin(views=[UserAdmin], engine=engine)
plugins = [admin]
# Works fine without the StructlogPlugin; but adding the structlog plugin causes errors when creating/editing items in the admin page!
plugins.append(StructlogPlugin())
app = Litestar(plugins=plugins, on_startup=[on_startup])
1. Run example
2. Go to localhost/admin
3. Try to create/edit an user
4. Internal Server Error 500
"path": "/user/edit/1/",
"exception_0": {
"summary": "AttributeError('ASGIRouteHandler' object has no attribute 'resolve_request_max_body_size')",
"frames": [
"data_extractors.py:303 (in ConnectionDataExtractor.extract_body)",
"request.py:267 (in HTMXRequest.form)",
"_multipart.py:78 (in parse_multipart_form)",
"request.py:193 (in HTMXRequest.stream)"
]
},
"exception_1": {
"summary": "AttributeError('ASGIRouteHandler' object has no attribute 'resolve_request_max_body_size')",
"frames": [
"middleware.py:159 (in ExceptionHandlerMiddleware.__call__)",
"authentication.py:90 (in SessionAuthMiddleware.__call__)",
"base.py:129 (in LoggingMiddleware.wrapped_call)",
"logging.py:110 (in LoggingMiddleware.__call__)",
"logging.py:124 (in LoggingMiddleware.log_request)",
"logging.py:174 (in LoggingMiddleware.extract_request_data)",
"data_extractors.py:172 (in ConnectionDataExtractor.extract)",
"data_extractors.py:311 (in ConnectionDataExtractor.extract_body)",
"request.py:252 (in HTMXRequest.body)",
"request.py:193 (in HTMXRequest.stream)"
]
}
2.14.0
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too