Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Some products have empty names, skip them

Roland Geiderdc1a4d1d83c9
diff --git a/wger/nutrition/off.py b/wger/nutrition/off.py
index 9423fa216..57ac8be2e 100644
--- a/wger/nutrition/off.py
+++ b/wger/nutrition/off.py
@@ -22,7 +22,6 @@ from wger.nutrition.models import Source
from wger.utils.constants import ODBL_LICENSE_ID
from wger.utils.models import AbstractSubmissionModel
-
OFF_REQUIRED_TOP_LEVEL = [
'product_name',
'code',
@@ -43,9 +42,9 @@ def extract_info_from_off(product_data: dict, language: int) -> IngredientData:
raise KeyError('Missing required nutrition key')
# Basics
- name = product_data['product_name']
- if name is None:
- raise KeyError('Product name is None')
+ name = product_data.get('product_name')
+ if not name:
+ raise KeyError('Product name is empty')
if len(name) > 200:
name = name[:200]
diff --git a/wger/nutrition/usda.py b/wger/nutrition/usda.py
index 2c360fb1d..1683bdacb 100644
--- a/wger/nutrition/usda.py
+++ b/wger/nutrition/usda.py
@@ -92,6 +92,8 @@ def extract_info_from_usda(product_data: dict, language: int) -> IngredientData:
raise ValueError(f'Value for macronutrient is greater than 100! {macros=} {remote_id=}')
name = product_data['description'].title()
+ if not name:
+ raise ValueError(f'Name is empty! {remote_id=}')
if len(name) > 200:
name = name[:200]