Skip to content

Commit 79a2ba8

Browse files
committed
🚨 Fix mypy warnings about primary_key in fieldInfo
1 parent 76d72cd commit 79a2ba8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sqlmodel/_compat.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ def validate_access_primary_key_autotype(
240240
if name != "model_fields":
241241
model_fields = object.__getattribute__(self, "model_fields")
242242
field = model_fields.get(name)
243-
if field is not None and isinstance(field, FieldInfo):
243+
if (
244+
field is not None
245+
and isinstance(field, FieldInfo)
246+
and hasattr(field, "primary_key")
247+
):
244248
if field.primary_key and field.annotation is int and value is None:
245249
raise ValueError(
246250
f"Primary key attribute '{name}' has not been set, please commit() it first."
@@ -547,7 +551,11 @@ def validate_access_primary_key_autotype(
547551
if name != "__fields__":
548552
fields = object.__getattribute__(self, "__fields__")
549553
field = fields.get(name)
550-
if field is not None and isinstance(field.field_info, FieldInfo):
554+
if (
555+
field is not None
556+
and isinstance(field.field_info, FieldInfo)
557+
and hasattr(field.field_info, "primary_key")
558+
):
551559
if (
552560
field.field_info.primary_key
553561
and field.annotation is int

0 commit comments

Comments
 (0)