Bug/error relating units foods (#987)

* fix type guard

* update typing

* rearrange methods

* spelling

* fix unknown error response

* update type check for none types

* add discord notification
This commit is contained in:
Hayden
2022-02-21 09:47:00 -09:00
committed by GitHub
parent 5310a94478
commit a897e180ed
5 changed files with 38 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
from functools import wraps
from uuid import UUID
from pydantic import BaseModel, Field
from sqlalchemy.orm import MANYTOMANY, MANYTOONE, ONETOMANY, Session
@@ -170,9 +171,13 @@ def auto_init(): # sourcery no-metrics
if val is None:
raise ValueError(f"Expected 'id' to be provided for {key}")
if isinstance(val, (str, int)):
if isinstance(val, (str, int, UUID)):
instance = session.query(relation_cls).filter_by(**{get_attr: val}).one_or_none()
setattr(self, key, instance)
else:
# If the value is not of the type defined above we assume that it isn't a valid id
# and try a different approach.
pass
elif relation_dir == MANYTOMANY:
instances = handle_many_to_many(session, get_attr, relation_cls, val)

View File

@@ -142,7 +142,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
assets: list = None,
notes: list[dict] = None,
nutrition: dict = None,
recipe_ingredient: list[str] = None,
recipe_ingredient: list[dict] = None,
settings: dict = None,
**_,
) -> None: