mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-16 04:43:13 -05:00
fix: Pydantic Serialization Issues (#3157)
* replaced pydantic inits with validators * fixed serialization dropping food and unit ids
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import UUID4, ConfigDict, field_validator
|
||||
from pydantic import UUID4, ConfigDict, field_validator, model_validator
|
||||
from sqlalchemy.orm import joinedload, selectinload
|
||||
from sqlalchemy.orm.interfaces import LoaderOption
|
||||
|
||||
@@ -100,14 +100,15 @@ class ShoppingListItemOut(ShoppingListItemBase):
|
||||
created_at: datetime | None = None
|
||||
update_at: datetime | None = None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def post_validate(self):
|
||||
# if we're missing a label, but the food has a label, use that as the label
|
||||
if (not self.label) and (self.food and self.food.label):
|
||||
self.label = self.food.label
|
||||
self.label_id = self.label.id
|
||||
|
||||
return self
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user