feat: add SQLModel compatibility#686
Merged
cofin merged 9 commits intolitestar-org:mainfrom Mar 8, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #686 +/- ##
==========================================
+ Coverage 80.67% 80.85% +0.18%
==========================================
Files 99 99
Lines 8177 8176 -1
Branches 1121 1119 -2
==========================================
+ Hits 6597 6611 +14
+ Misses 1249 1240 -9
+ Partials 331 325 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Widen ModelProtocol to accept SQLModel table=True models by removing the to_dict() requirement. Add model_to_dict() utility that delegates to to_dict() for AA models and falls back to mapper-based column iteration for SQLModel and other mapped models. Add is_sqlmodel_table_model() detection to prevent the service layer from misidentifying SQLModel table instances as plain Pydantic schemas in schema_dump() and to_model().
The is_schema() family of functions incorrectly identified SQLModel table=True models as schemas via the is_pydantic_model() check, causing them to be decomposed into dicts instead of treated as ORM models.
Add sqlmodel as a test dependency and expand test coverage with model_from_dict, get_primary_key_info, get_instrumented_attr, and roundtrip tests for SQLModel table models.
Use cast() at call sites where SQLModel table=True models are passed to functions typed with ModelProtocol. SQLModel's metaclass adds __mapper__ and __table__ dynamically, which satisfies ModelProtocol at runtime but is invisible to static analysis. Also fix pyright errors in model_to_dict by using getattr for duck-typed to_dict access and explicit type annotations.
Add SQLModel compatibility, composite primary keys, read/write replica routing, dogpile caching, and NULL filters to the feature list.
…coverage Add tests for update_many, upsert, and upsert fallback-match-by-all-fields using an in-memory SQLite database with SQLModel table models.
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.
Summary
table=Truemodels now work seamlessly with Advanced Alchemy repositories and services without requiring AA base classesModelProtocolno longer requiresto_dict()— models only need__mapper__,__table__, and__name__(which all SQLAlchemy-mapped models have)model_to_dict()utility converts any mapped model to a dict using mapper column introspectionis_schema()family of functions now correctly exclude SQLModel table models (they are ORM models, not transfer schemas)schema_dump()returns SQLModel table instances as-is instead of callingmodel_dump()is_sqlmodel_table_model()detection functionChanges
base.pyModelProtocol(removedto_dictrequirement), addedmodel_to_dict()service/typing.pyis_sqlmodel_table_model(), updatedis_schema()family to exclude table models, updatedschema_dump()service/_async.py/_sync.pyto_model()repository/_async.py/_sync.pyto_model()service/_typing.pySQLMODEL_INSTALLEDflagpyproject.tomlsqlmodelto test dependenciestests/unit/test_sqlmodel_compat.py