From f6167b1d81a22b4b4a791e87c1b7a08d13005bc6 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Mon, 12 Feb 2024 05:26:53 +0000 Subject: [PATCH] add id validator for empty strings --- mealie/schema/recipe/recipe_ingredient.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mealie/schema/recipe/recipe_ingredient.py b/mealie/schema/recipe/recipe_ingredient.py index 2d0ec633dace..5eaa0e9f12c3 100644 --- a/mealie/schema/recipe/recipe_ingredient.py +++ b/mealie/schema/recipe/recipe_ingredient.py @@ -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):