Skip to content

Commit e33be86

Browse files
fix: use annotated functional validators
1 parent 86846a6 commit e33be86

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/models-library/src/models_library/projects.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from common_library.basic_types import DEFAULT_FACTORY
1111
from pydantic import (
1212
BaseModel,
13+
BeforeValidator,
1314
ConfigDict,
1415
Field,
1516
HttpUrl,
@@ -85,13 +86,17 @@ class BaseProjectModel(BaseModel):
8586
]
8687
description: Annotated[
8788
str,
89+
BeforeValidator(none_to_empty_str_pre_validator),
8890
Field(
8991
description="longer one-line description about the project",
9092
examples=["Dabbling in temporal transitions ..."],
9193
),
9294
]
9395
thumbnail: Annotated[
9496
HttpUrl | None,
97+
BeforeValidator(
98+
empty_str_to_none_pre_validator,
99+
),
95100
Field(
96101
description="url of the project thumbnail",
97102
examples=["https://placeimg.com/171/96/tech/grayscale/?0.jpg"],
@@ -105,15 +110,6 @@ class BaseProjectModel(BaseModel):
105110
# FIXME: pedro removes this one
106111
workbench: Annotated[NodesDict, Field(description="Project's pipeline")]
107112

108-
# validators
109-
_empty_thumbnail_is_none = field_validator("thumbnail", mode="before")(
110-
empty_str_to_none_pre_validator
111-
)
112-
113-
_none_description_is_empty = field_validator("description", mode="before")(
114-
none_to_empty_str_pre_validator
115-
)
116-
117113

118114
class ProjectAtDB(BaseProjectModel):
119115
# Model used to READ from database

0 commit comments

Comments
 (0)