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
TypeAdapter defer_build not working as expected #8716
Comments
TypeAdapter can not be used in nested schemas and does not work with delayed initialization/defer_build pydantic/pydantic#8716
TypeAdapter can not be used in nested schemas and does not work with delayed initialization/defer_build pydantic/pydantic#8716
Thanks for reporting this. Indeed, this looks like a bug. I suspect that a fix for this issue might look like that which I've implemented here for a similar issue: #7736. Any interest in opening a PR with a fix? |
Hmm. After thinking about this more - |
I think we both initially expected this to work. |
TypeAdapter was never meant to be a field of a model. You’re supposed to just use the model, or a generic, for that. I’m also confused by the |
Also, we could add a |
I'd need TypeAdapter to behave "as models" basically as container for generics, which is not intended use. Using __types prevents name lookup collisions/confusion during construction. |
Given that, I think we can mark this issue as not planned, given that the features you're requesting are supported for Thanks for your feedback. Happy coding! |
Initial Checks
Description
I'm with the client side of OpenAPI, create models dynamically using create_model after parsing a OpenAPI description document.
Creating models dynamically requires delayed initialization, which works fine for BaseModel/RootModel.
Using TypeAdapter delayed initialization does not work.
I was hoping to skip a RootModels .root reference (for nullable objects) when using the TypeAdapter instead.
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: