From 79a2ba84e5eb5bd9fb84ddd6e2ae9c248e3ec243 Mon Sep 17 00:00:00 2001 From: Esteban Maya Cadavid Date: Wed, 3 Jul 2024 08:47:27 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20mypy=20warnings=20about=20?= =?UTF-8?q?primary=5Fkey=20in=20fieldInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqlmodel/_compat.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 02d5613..04ebeda 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