Skip to content

✨ Add support for SQLAlchemy polymorphic models #1226

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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6d93a46
support sqlalchemy polymorphic
Nov 26, 2024
589237b
improve docs
Nov 26, 2024
4071b0f
fix polymorphic_on check
Nov 26, 2024
48f2a88
fix polymorphic_on check
Nov 26, 2024
e6ad74d
fix lint
Nov 26, 2024
277953a
fix pydantic v1 support
Nov 26, 2024
4aade03
fix type hint for <3.10
Nov 26, 2024
a3044bb
add needs_pydanticv2 mark to test
Nov 26, 2024
015601c
improve code structure
Dec 3, 2024
66c1d93
lint
Dec 3, 2024
0efd1bf
remove effort of pydantic v1
Dec 3, 2024
7173b44
Merge branch 'main' into sqlalchemy_polymorphic_support
PaleNeutron Dec 10, 2024
84d739e
Update sqlmodel/_compat.py
PaleNeutron Dec 12, 2024
dbd0101
fix default value is InstrumentedAttribute in inherit
Feb 5, 2025
88670a5
Merge branch 'sqlalchemy_polymorphic_support' of https://github.com/P…
Feb 5, 2025
b1ed8c3
fix inherit order
Feb 5, 2025
5d1bf5c
support python < 3.9
Feb 5, 2025
ccbb92a
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2025
d0d0288
skip polymorphic in pydantic v1
Feb 5, 2025
525373d
Merge branch 'sqlalchemy_polymorphic_support' of https://github.com/P…
Feb 5, 2025
ab965f0
Merge branch 'main' into sqlalchemy_polymorphic_support
PaleNeutron Feb 5, 2025
68963e7
Merge branch 'main' into sqlalchemy_polymorphic_support
svlandeg Feb 20, 2025
95c6a1e
Merge branch 'main' into sqlalchemy_polymorphic_support
svlandeg Feb 24, 2025
c1dff79
disable pydantic warning during polymorphic
Mar 12, 2025
7d333fe
fix relationship problem of parent class during polymorphic inherit
May 15, 2025
32ebd6f
avoid add ClassVar multiple times
May 15, 2025
64f774f
Add support for polymorphic_abstract
May 27, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid add ClassVar multiple times
  • Loading branch information
John Lyu committed May 15, 2025
commit 32ebd6f2a0c6f0aa46f8c1f1f4178fe084c65f54
5 changes: 3 additions & 2 deletions sqlmodel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,9 @@ def __new__(
# create a dummy attribute to avoid inherit
# pydantic will treat it as class variables, and will not become fields on model instances
anno = base_annotations.get(k, Any)
dummy_anno = ClassVar[anno]
dict_used["__annotations__"][k] = dummy_anno
if get_origin(anno) is not ClassVar:
dummy_anno = ClassVar[anno]
dict_used["__annotations__"][k] = dummy_anno

if hasattr(base, "__tablename__"):
is_polymorphic = True
Expand Down