| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
This was marked as potentially AI generated and will be closed now. If this is an error, please provide additional details, make sure to read the docs about contributing and AI. |
Sorry, something went wrong.
|
@svlandeg Hi, just wanted to let you know this is not a automated PR, though I did use AI to help me out, mostly for porting sqlalchemy inheritance tests to sqlmodel, to make sure the feature behaves as expected. Please let me know what I need to do to get the approval. Thanks. |
Sorry, something went wrong.
|
Why is this closed? |
Sorry, something went wrong.
|
I'll open it back up for review. |
Sorry, something went wrong.
|
This pull request has a merge conflict that needs to be resolved. |
Sorry, something went wrong.
… and single-table inheritance)
…ctors and assignment
|
Is there anything we can do to help out on this ? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR builds on top of #1226 and completes support for SQLAlchemy single-table and joined-table polymorphic inheritance in SQLModel.
#1226 had some problems:
We fix these issues in this PR and add a more complete test suite.
Commit structure
This PR is quite large (mainly due to tests), so the commits are split to make review easier.
1. Add metaclass support for SQLAlchemy polymorphic models
Adds support for both joined-table and single-table inheritance.
This commit:
2. Fix inherited relationship resolution in polymorphic subclasses
sqlmodel_table_construct and sqlmodel_validate previously iterated only over __sqlmodel_relationships__, which missed relationships inherited from polymorphic base classes.
This commit replaces that logic with _relationship_keys(), which falls back to the SQLAlchemy mapper when available.
It also fixes SQLModel.__setattr__, which now detects mapper-owned relationships with _is_sqlmodel_relationship() and lets SQLAlchemy handle the assignment instead of forwarding the inherited relationship assignments to Pydantic.
3. Add polymorphic inheritance test suite
Adds a large test suite under tests/test_polymorphic/.
Most tests are ported from SQLAlchemy's own inheritance test suite, test/orm/inheritance/, and adapted to SQLModel's API.
The suite also covers issues raised in #1226 comments:
✨ Add support for SQLAlchemy polymorphic models #1226 (comment)
Custom TypeDecorator + polymorphic model pickle error
Covered by test_polymorphic_typedecorator.py
✨ Add support for SQLAlchemy polymorphic models #1226 (comment)
Self-referential relationship assignment on polymorphic subclasses
Covered by test_poly_linked_list.py
✨ Add support for SQLAlchemy polymorphic models #1226 (comment)
Relationships with polymorphic subclasses
Covered by test_polymorphic_constructor.py, and test_manytomany.py