Merge pull request #3160 from michael-genson/fix/coerce-empty-string-to-none

fix: Pydantic Validation For Empty ID String
This commit is contained in:
boc-the-git 2024-02-12 19:36:21 +11:00 committed by GitHub
commit ae03e61bb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,6 +37,15 @@ class UnitFoodBase(MealieModel):
description: str = ""
extras: dict | None = {}
@field_validator("id", mode="before")
def convert_empty_id_to_none(cls, v):
# sometimes the frontend will give us an empty string instead of null, so we convert it to None,
# otherwise Pydantic will try to convert it to a UUID and fail
if not v:
v = None
return v
@field_validator("extras", mode="before")
def convert_extras_to_dict(cls, v):
if isinstance(v, dict):