Replies: 4 comments 7 replies
-
Hi, @downdawn Do you have any good ideas? |
Beta Was this translation helpful? Give feedback.
2 replies
-
For Enum type data, add a validator and return value class Pdv(BaseModel):
num: IntType = IntType.a
@validator('num')
def num_validator(cls, v):
return v.value |
Beta Was this translation helpful? Give feedback.
1 reply
-
Another option, custom validation exceptions class Pdv(BaseModel):
num: int = IntType.a
@validator('num')
def num_validator(cls, v):
if v not in Pdv.get_member_values():
raise ValueError('Invalid num value, permitted: 1, 2')
return v |
Beta Was this translation helpful? Give feedback.
4 replies
-
错过了官方文档,只需
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Use Enum type validation in pydantic, e.g.
This method does enum validation, but dict() returns the IntType instance instead of the value
Type errors are usually raised when storing the database
Beta Was this translation helpful? Give feedback.
All reactions