File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ class UserOut(UserBase):
107
107
group_slug : str
108
108
tokens : list [LongLiveTokenOut ] | None = None
109
109
cache_key : str
110
- favorite_recipes : Annotated [list [str ] | None , Field (validate_default = True )] = []
110
+ favorite_recipes : Annotated [list [str ], Field (validate_default = True )] = []
111
111
model_config = ConfigDict (from_attributes = True )
112
112
113
113
@property
@@ -119,8 +119,18 @@ def loader_options(cls) -> list[LoaderOption]:
119
119
return [joinedload (User .group ), joinedload (User .favorite_recipes ), joinedload (User .tokens )]
120
120
121
121
@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
124
134
125
135
126
136
class UserPagination (PaginationBase ):
You can’t perform that action at this time.
0 commit comments