升级Pydantic版本后遭遇基类字段被非注解属性覆盖报错的问题求助
升级Pydantic版本后遭遇基类字段被非注解属性覆盖报错的问题求助
我最近升级了Pydantic的版本,结果代码直接跑不起来了,报了这个错误:
Field 'allowed_type' defined on a base class
was overridden by a non-annotated attribute. All field
definitions, including overrides, require a type
annotation.
我的代码如下:
枚举类定义:
class AllowedType(str, Enum): YES = "YES" NO = "NO"
模型类定义:
class APIResponse(BaseModel): allowed_type: AllowedType def to_json(self): return json.dumps( { "allowed_type": self.allowed_type, } )
我尝试了Pydantic官方针对这个错误给出的所有解决方案,但都没起作用,有没有大佬能帮我排查下问题出在哪?
备注:内容来源于stack exchange,提问作者Tanu
相关产品推荐
相关产品推荐

