From b2785dd46f9c32a5a7e07aac09a739171f8f51fc Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Sun, 18 Jan 2026 23:43:33 +0800 Subject: [PATCH] Fix snowflake type primary key field serializer (#1024) --- backend/common/schema.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/common/schema.py b/backend/common/schema.py index b64da0b2..1e0d3400 100644 --- a/backend/common/schema.py +++ b/backend/common/schema.py @@ -37,8 +37,10 @@ class SchemaBase(BaseModel): # 详情:https://fastapi-practices.github.io/fastapi_best_architecture_docs/backend/reference/pk.html#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9 @field_serializer('id', check_fields=False) - def serialize_id(self, value: int) -> str: - return str(value) + def serialize_id(self, value: int) -> str | int: + if self.model_config.get('from_attributes'): + return str(value) + return value def ser_string(value: Any) -> str | None: