Skip to content

Commit 2592e72

Browse files
committed
add field validator to parse ‘labels’ field
1 parent 27c10d5 commit 2592e72

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

app/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import json
12
import uuid
23
from datetime import date, datetime
34

5+
from pydantic import field_validator
46
from sqlmodel import JSON, Column, DateTime, Field, SQLModel, func
57

68

@@ -18,6 +20,12 @@ class ModelBase(SQLModel):
1820
last_updated_str: str
1921
url: str
2022

23+
@field_validator("labels", mode="before")
24+
def parse_labels(cls, v):
25+
if isinstance(v, str):
26+
return json.loads(v)
27+
return v
28+
2129
class Config:
2230
protected_namespaces = ()
2331

0 commit comments

Comments
 (0)