From fab1e327aa5024e36f809ac0df5f57f303f90b65 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 26 Jun 2024 16:13:08 -0300 Subject: [PATCH] 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. --- .../langflow/services/database/models/message/model.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/base/langflow/services/database/models/message/model.py b/src/backend/base/langflow/services/database/models/message/model.py index 128088398..69b461753 100644 --- a/src/backend/base/langflow/services/database/models/message/model.py +++ b/src/backend/base/langflow/services/database/models/message/model.py @@ -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