Skip to content

Commit b867ad7

Browse files
committed
Fix inheritance when getting annotations
1 parent 28445d1 commit b867ad7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

sqlmodel/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,11 @@ def get_config(name: str) -> Any:
567567
if isinstance(original_field, FieldInfo):
568568
field = original_field
569569
else:
570-
annotated_field = get_annotations(new_cls.__dict__).get(k, {})
570+
annotated_field = next(
571+
ann
572+
for c in new_cls.__mro__
573+
if (ann := get_annotations(c.__dict__).get(k))
574+
)
571575
annotated_field_meta = getattr(
572576
annotated_field, "__metadata__", (())
573577
)

tests/test_declaration_syntax.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44

55

66
def test_declaration_syntax_1():
7-
class Person1(SQLModel, table=True):
7+
class Person1(SQLModel):
88
name: str = Field(primary_key=True)
99

10+
class Person1Final(Person1, table=True):
11+
pass
12+
1013

1114
def test_declaration_syntax_2():
12-
class Person2(SQLModel, table=True):
15+
class Person2(SQLModel):
1316
name: Annotated[str, Field(primary_key=True)]
1417

18+
class Person2Final(Person2, table=True):
19+
pass
20+
1521

1622
def test_declaration_syntax_3():
17-
class Person3(SQLModel, table=True):
23+
class Person3(SQLModel):
1824
name: Annotated[str, ...] = Field(primary_key=True)
25+
26+
class Person3Final(Person3, table=True):
27+
pass

0 commit comments

Comments
 (0)