Skip to content

Commit 48fb200

Browse files
added failsafe for bad input data
1 parent 05e13e6 commit 48fb200

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mealie/schema/user/user.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime, timedelta
22
from pathlib import Path
3-
from typing import Annotated
3+
from typing import Annotated, Any
44
from uuid import UUID
55

66
from pydantic import UUID4, ConfigDict, Field, StringConstraints, field_validator
@@ -119,16 +119,22 @@ def loader_options(cls) -> list[LoaderOption]:
119119
return [joinedload(User.group), joinedload(User.favorite_recipes), joinedload(User.tokens)]
120120

121121
@field_validator("favorite_recipes", mode="before")
122-
def convert_favorite_recipes_to_slugs(cls, v: list[str | RecipeSummary] | None):
122+
def convert_favorite_recipes_to_slugs(cls, v: list | None):
123123
if not v:
124124
return []
125+
if not isinstance(v, list):
126+
return v
125127

126128
slugs: list[str] = []
127129
for recipe in v:
128130
if isinstance(recipe, str):
129131
slugs.append(recipe)
130132
else:
131-
slugs.append(recipe.slug)
133+
try:
134+
slugs.append(recipe.slug)
135+
except AttributeError:
136+
# this isn't a list of recipes, so we quit early and let Pydantic's typical validation handle it
137+
return v
132138

133139
return slugs
134140

0 commit comments

Comments
 (0)