Skip to content

Commit 6ddb872

Browse files
committed
fix: 尝试修复 3.10 以及以下序列化 message 时 RetCode 序列化为枚举名称的问题
1 parent 8229703 commit 6ddb872

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pydglab_ws/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
此处定义了一些 Pydantic 模型,使用 Pydantic V2
33
"""
4+
from enum import IntEnum
45
from typing import Optional, Any, Union
56

67
from pydantic import BaseModel, UUID4, ConfigDict, field_serializer, AliasGenerator, model_validator, \
@@ -53,8 +54,8 @@ def _validate_message(cls, value: Any):
5354
@field_serializer("message", mode="wrap")
5455
def _serialize_message(self, value: Any, nxt: SerializerFunctionWrapHandler, _: FieldSerializationInfo):
5556
"""对于 ``IntEnum`` 的枚举,转化为 ``str``"""
56-
if isinstance(value, int):
57-
return str(value)
57+
if isinstance(value, IntEnum):
58+
return str(value.value)
5859
else:
5960
return nxt(value)
6061

0 commit comments

Comments
 (0)