feat: Add field validation for flow_id in MessageTable model
This commit adds field validation for the `flow_id` attribute in the `MessageTable` model. The `validate_flow_id` class method is implemented to ensure that the `flow_id` value is either `None` or a valid UUID. This validation helps maintain data integrity and consistency when working with the `MessageTable` model.
This commit is contained in:
parent
802425c7de
commit
fab1e327aa
1 changed files with 9 additions and 0 deletions
|
|
@ -54,6 +54,15 @@ class MessageTable(MessageBase, table=True):
|
|||
flow: "Flow" = Relationship(back_populates="messages")
|
||||
files: List[str] = Field(sa_column=Column(JSON))
|
||||
|
||||
@field_validator("flow_id", mode="before")
|
||||
@classmethod
|
||||
def validate_flow_id(cls, value):
|
||||
if value is None:
|
||||
return value
|
||||
if isinstance(value, str):
|
||||
value = UUID(value)
|
||||
return value
|
||||
|
||||
# Needed for Column(JSON)
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue