From 48fb2008765f4ed5a2b57aa53cd3ca37bca49d50 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Mon, 11 Mar 2024 00:24:59 +0000 Subject: [PATCH] added failsafe for bad input data --- mealie/schema/user/user.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mealie/schema/user/user.py b/mealie/schema/user/user.py index f0a456bf713..66d072fa774 100644 --- a/mealie/schema/user/user.py +++ b/mealie/schema/user/user.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta from pathlib import Path -from typing import Annotated +from typing import Annotated, Any from uuid import UUID from pydantic import UUID4, ConfigDict, Field, StringConstraints, field_validator @@ -119,16 +119,22 @@ def loader_options(cls) -> list[LoaderOption]: return [joinedload(User.group), joinedload(User.favorite_recipes), joinedload(User.tokens)] @field_validator("favorite_recipes", mode="before") - def convert_favorite_recipes_to_slugs(cls, v: list[str | RecipeSummary] | None): + def convert_favorite_recipes_to_slugs(cls, v: list | None): if not v: return [] + if not isinstance(v, list): + return v slugs: list[str] = [] for recipe in v: if isinstance(recipe, str): slugs.append(recipe) else: - slugs.append(recipe.slug) + try: + slugs.append(recipe.slug) + except AttributeError: + # this isn't a list of recipes, so we quit early and let Pydantic's typical validation handle it + return v return slugs