From: Esteban Maya Cadavid Date: Wed, 3 Jul 2024 13:47:27 +0000 (-0500) Subject: 🚨 Fix mypy warnings about primary_key in fieldInfo X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79a2ba84e5eb5bd9fb84ddd6e2ae9c248e3ec243;p=thirdparty%2Ffastapi%2Fsqlmodel.git 🚨 Fix mypy warnings about primary_key in fieldInfo --- diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 02d56135..04ebeda0 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -240,7 +240,11 @@ if IS_PYDANTIC_V2: if name != "model_fields": model_fields = object.__getattribute__(self, "model_fields") field = model_fields.get(name) - if field is not None and isinstance(field, FieldInfo): + if ( + field is not None + and isinstance(field, FieldInfo) + and hasattr(field, "primary_key") + ): if field.primary_key and field.annotation is int and value is None: raise ValueError( f"Primary key attribute '{name}' has not been set, please commit() it first." @@ -547,7 +551,11 @@ else: if name != "__fields__": fields = object.__getattribute__(self, "__fields__") field = fields.get(name) - if field is not None and isinstance(field.field_info, FieldInfo): + if ( + field is not None + and isinstance(field.field_info, FieldInfo) + and hasattr(field.field_info, "primary_key") + ): if ( field.field_info.primary_key and field.annotation is int