Repository navigation
pydantic + sqlmodel namespace hooks for lazy forward-ref resolution - #12
Merged
Merged
Conversation
adsharma
force-pushed
the
pydantic_namespaces
branch
from
September 18, 2026 19:38
bba8675 to
108acb5
Compare
Mirror fquery.pydantic's hook: sqlmodel() and model() accept namespace= (static mapping or callable taking the decorated class), stored as __sqlmodel_namespace__ and inherited unless overridden. Threaded into get_type_hints() call sites and a post-build rebuild that prefers sqlmodel_rebuild (fork) with model_rebuild fallback. Table creation itself stays eager; only name resolution is hooked. Also fix get_field_type() to use the resolved hint target instead of the raw annotation, which may still be a ForwardRef for string-form fields like Optional["Widget"].
model()/pydantic() accept namespace= (static mapping or callable taking the decorated class). validator() rebuilds incomplete models via a shared helper seeded from the MRO plus module globals, merged with the hook result, with bounded retries on NameError. Lets consumers with hundreds of lazily-imported models (e.g. schema-org-python) supply forward-ref targets on demand instead of importing everything up front. The hook is inherited by subclasses unless overridden.
Appending the package dir to sys.path made fquery/ladybug.py shadow the real ladybug package, breaking 'import ladybug' in tox (relative import error aborted collection). pytest.importorskip now skips cleanly when the dependency is missing.
adsharma
force-pushed
the
pydantic_namespaces
branch
from
September 18, 2026 19:52
108acb5 to
b20d7fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
namespace=to fquery'spydantic/modelandsqlmodel/modeldecorators (static mapping or callable) so consumers with lazily-imported models can supply forward-ref targets on demand.Commits: