Self hosted FLOSS fitness/workout, nutrition and weight tracker
Seems it's possible for a product to not have "lang" key
Roland Geider5b6b03585086
diff --git a/wger/nutrition/management/commands/import-off-products.py b/wger/nutrition/management/commands/import-off-products.pyindex 174d49e53..ddf072635 100644--- a/wger/nutrition/management/commands/import-off-products.py+++ b/wger/nutrition/management/commands/import-off-products.py@@ -28,7 +28,6 @@ from wger.nutrition.management.products import ()from wger.nutrition.off import extract_info_from_off-logger = logging.getLogger(__name__)@@ -91,12 +90,13 @@ class Command(ImportProductCommand):delta_url = self.deltas_base_url + newest_entryself.download_file(delta_url, file_path)+ self.stdout.write('Start processing...')for entry in self.iterate_gz_file_contents(file_path, list(languages.keys())):try:ingredient_data = extract_info_from_off(entry, languages[entry['lang']])except (KeyError, ValueError) as e:self.stdout.write(- f'--> {ingredient_data.remote_id=} KeyError while extracting info from OFF: {e}'+ f'--> {ingredient_data.remote_id=} Error while extracting info from OFF: {e}')self.counter['skipped'] += 1else:@@ -112,11 +112,12 @@ class Command(ImportProductCommand):file_path = os.path.join(download_folder, os.path.basename(self.full_off_dump_url))self.download_file(self.full_off_dump_url, file_path)+ self.stdout.write('Start processing...')for entry in self.iterate_gz_file_contents(file_path, list(languages.keys())):try:ingredient_data = extract_info_from_off(entry, languages[entry['lang']])except (KeyError, ValueError) as e:- # self.stdout.write(f'--> KeyError while extracting info from OFF: {e}')+ self.stdout.write(f'--> Error while extracting info from OFF: {e}')self.counter['skipped'] += 1else:self.process_ingredient(ingredient_data)diff --git a/wger/nutrition/management/products.py b/wger/nutrition/management/products.pyindex 86cc0b611..5799fb7a6 100644--- a/wger/nutrition/management/products.py+++ b/wger/nutrition/management/products.py@@ -35,7 +35,6 @@ from wger.nutrition.dataclasses import IngredientDatafrom wger.nutrition.models import Ingredientfrom wger.utils.requests import wger_headers-logger = logging.getLogger(__name__)@@ -168,10 +167,10 @@ class ImportProductCommand(BaseCommand):for line in gzid:try:product = json.loads(line)- if not product['lang'] in languages:+ if not product.get('lang') in languages:continueyield product- except JSONDecodeError as e:+ except JSONDecodeError:self.stdout.write(f' Error parsing and/or filtering json record, skipping')continue