-
-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug(SQLAlchemy Plugin): Generic responses are not getting serialized #3553
Labels
Bug 🐛
This is something that is not working as expected
Comments
Another MCVE that seams to be causing this issue as discussed on discord (an example from the docs wrapped with MVCEimport uuid
from dataclasses import dataclass
from datetime import datetime
from typing import Generic, TypeVar
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from sqlalchemy import text
from sqlalchemy import Uuid
from sqlalchemy.orm import DeclarativeBase
from litestar import Litestar, get
from litestar import Response
from litestar.contrib.sqlalchemy.dto import SQLAlchemyDTO
from litestar.dto import DTOConfig
T = TypeVar("T")
class Base(DeclarativeBase):
pass
@dataclass
class WithCount(Generic[T]):
count: int
data: list[T]
class User(Base):
__tablename__ = "user"
id: Mapped[uuid.UUID] = mapped_column(
Uuid(as_uuid=True, native_uuid=True),
primary_key=True,
nullable=False,
server_default=text("gen_random_uuid()"),
)
name: Mapped[str]
password: Mapped[str]
created_at: Mapped[datetime]
class UserDTO(SQLAlchemyDTO[User]):
config = DTOConfig(exclude={"password", "created_at"})
@get("/api/users", dto=UserDTO, sync_to_thread=False)
def get_users() -> Response[WithCount[User]]:
return Response(
WithCount(
count=1,
data=[
User(
id=uuid.uuid4(),
name="Litestar User",
password="xyz",
created_at=datetime.now(),
),
],
)
)
api = Litestar(route_handlers=[get_users], debug=True) crashes when requesting Logs:
|
Thanks I have added the use case to the tests above |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
If the return type of a route has more than one field which is generic on one or two (possibly more?) types the expected serialization does not occur.
TL;DR
Current behavior: Serialization Fails for all routes except
route-0
Expected behavior: Serialization Success
URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Logs
Litestar Version
84f51c8 (main as of issue creation)
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: