refactor: Add field_validator for files in MessageBase model
This commit is contained in:
parent
2637e8e349
commit
5bdd035dc3
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 typing import TYPE_CHECKING, List, Optional
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
|
from pydantic import field_validator
|
||||||
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -17,6 +18,13 @@ class MessageBase(SQLModel):
|
||||||
text: str
|
text: str
|
||||||
files: list[str] = Field(default_factory=list)
|
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
|
@classmethod
|
||||||
def from_message(cls, message: "Message", flow_id: str | None = None):
|
def from_message(cls, message: "Message", flow_id: str | None = None):
|
||||||
# first check if the record has all the required fields
|
# first check if the record has all the required fields
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue