fix: Ingredient Parser Drops Units Sometimes (#6150)

This commit is contained in:
Michael Genson
2025-09-13 15:49:08 -05:00
committed by GitHub
parent 8cd5835dd8
commit d4f4ba0c8d
2 changed files with 9 additions and 7 deletions

View File

@@ -161,12 +161,15 @@ class ABCIngredientParser(ABC):
ingredient.ingredient.unit = unit_match
# Parser might have wrongly split a food into a unit and food.
if isinstance(ingredient.ingredient.food, CreateIngredientFood) and isinstance(
ingredient.ingredient.unit, CreateIngredientUnit
):
if food_match := self.data_matcher.find_food_match(
f"{ingredient.ingredient.unit.name} {ingredient.ingredient.food.name}"
):
food_is_matched = bool(ingredient.ingredient.food and ingredient.ingredient.food.id)
unit_is_matched = bool(ingredient.ingredient.unit and ingredient.ingredient.unit.id)
food_name = ingredient.ingredient.food.name if ingredient.ingredient.food else ""
unit_name = ingredient.ingredient.unit.name if ingredient.ingredient.unit else ""
if not food_is_matched and not unit_is_matched and food_name and unit_name:
food_match = self.data_matcher.find_food_match(f"{unit_name} {food_name}")
if food_match:
ingredient.ingredient.food = food_match
ingredient.ingredient.unit = None