Skip to content

Commit 05e13e6

Browse files
account for slugs or recipes when constructing user favorites
1 parent 5f6844e commit 05e13e6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mealie/schema/user/user.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class UserOut(UserBase):
107107
group_slug: str
108108
tokens: list[LongLiveTokenOut] | None = None
109109
cache_key: str
110-
favorite_recipes: Annotated[list[str] | None, Field(validate_default=True)] = []
110+
favorite_recipes: Annotated[list[str], Field(validate_default=True)] = []
111111
model_config = ConfigDict(from_attributes=True)
112112

113113
@property
@@ -119,8 +119,18 @@ 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):
123-
return [recipe.slug for recipe in v] if v else v
122+
def convert_favorite_recipes_to_slugs(cls, v: list[str | RecipeSummary] | None):
123+
if not v:
124+
return []
125+
126+
slugs: list[str] = []
127+
for recipe in v:
128+
if isinstance(recipe, str):
129+
slugs.append(recipe)
130+
else:
131+
slugs.append(recipe.slug)
132+
133+
return slugs
124134

125135

126136
class UserPagination(PaginationBase):

0 commit comments

Comments
 (0)