refactor: Add field_validator for files in MessageBase model
This commit is contained in:
parent
d1d5eb6e39
commit
5cefc8755b
1 changed files with 8 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ from datetime import datetime, timezone
|
|||
from typing import TYPE_CHECKING, List, Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from pydantic import field_validator
|
||||
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -17,6 +18,13 @@ class MessageBase(SQLModel):
|
|||
text: str
|
||||
files: list[str] = Field(default_factory=list)
|
||||
|
||||
@field_validator("files", mode="before")
|
||||
@classmethod
|
||||
def validate_files(cls, value):
|
||||
if not value:
|
||||
value = []
|
||||
return value
|
||||
|
||||
@classmethod
|
||||
def from_message(cls, message: "Message", flow_id: str | None = None):
|
||||
# first check if the record has all the required fields
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue