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
Add config.defer_build
to optionally make model building lazy
#6823
Conversation
please review. |
Having this as a config flag sounds reasonable to me. For the reasons discussed in #6768 I don’t think it’s good as a default, but for large apps it seems like a reasonable trade-off. Shouldn’t we make TypeAdapter lazy as well? |
Let's rename to |
Deploying with Cloudflare Pages
|
@@ -23,7 +23,7 @@ def __init__( | |||
code: PydanticErrorCodes, | |||
attempt_rebuild: Callable[[], SchemaValidator | None] | None = None, | |||
) -> None: | |||
"""Attempt rebuild.""" | |||
# debug(attempt_rebuild, code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should remove it
config.defer_model_build
to optionally make model building lazyconfig.defer_build
to optionally make model building lazy
aa034fb
to
709c4d4
Compare
Change Summary
This proposes a new config flag
defer_model_build
, when true this means the core schema, schema validator and schema serializer are not constructed for a model when it's defined, instead they're only built whenmodel_rebuild()
is called, or when the model is first called.Two reasons this can be useful:
TypeAdapter
s don't need all this logic calling - see Very slow (FastAPI) application startup after using V2 due to_core_utils.py:walk
#6768 and Pydantic v2 significantly slower than v1 #6748Related issue number
fix #6742
Checklist
ConfigDict
anyway, so I'll add more logic thenSelected Reviewer: @adriangb