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: openapi schema generation fails for Union of/in msgspec.Struct models #2971
Comments
Thanks for report @aedify-swi, confirmed. Guessing that you are using 3.8 or 3.9 in prod app with Issue is with our internal schema generation plugin for litestar/litestar/_openapi/schema_generation/plugins/struct.py Lines 21 to 22 in cc45c11
Changing that to: def is_plugin_supported_field(self, field_definition: FieldDefinition) -> bool:
return not field_definition.is_union and field_definition.is_subclass_of(Struct) seems to sort it: |
Thanks for your quick reply @peterschutt!
Nope. 3.12 and exclusively |
Any chance you can provide a traceback for your prod issue please? |
Even better, I was able to reproduce it. import msgspec
import uvicorn
from litestar import Litestar, get
class SubStructA(msgspec.Struct):
a: int
class SubStructB(msgspec.Struct):
a: int
@get("/union")
async def testOptionalUnion() -> SubStructA | SubStructB | None:
return SubStructA(0)
app = Litestar(route_handlers=[testOptionalUnion]) # or test
uvicorn.run(app) This raises |
A fix for this issue has been released in v2.5.1 |
Description
Hello!
In the latest versions(s) (I think this originates from the changes regarding nested models in openapi generation) we cannot use Unions of
msgspec.Struct
s anymore. Neither as direct return types for routes nor nested within return types.The result is a 500 Error. The MCVE below raises
'types.UnionType' object has no attribute '__qualname__'
internally. In our production app I gettyping.Union is not a module, class, method, or function.
instead.Cheers
URL to code causing the issue
No response
MCVE
Steps to reproduce
Run the example and browse to `localhost:8000/schema`
Screenshots
No response
Logs
No response
Litestar Version
2.5.0
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: