From 861e8ac564e9df0a41620301e313d5333b572522 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Wed, 13 Dec 2023 04:31:13 -0600 Subject: [PATCH] fix: Paprika Migration Error (#2834) * made migration more fault tolerant * added edgecase for recipes with no ings/instructions * keep log for debugging --------- Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com> --- mealie/services/migrations/_migration_base.py | 6 +++++- mealie/services/migrations/paprika.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mealie/services/migrations/_migration_base.py b/mealie/services/migrations/_migration_base.py index 1268a38fb7c..383e71e26f3 100644 --- a/mealie/services/migrations/_migration_base.py +++ b/mealie/services/migrations/_migration_base.py @@ -209,7 +209,11 @@ def rewrite_alias(self, recipe_dict: dict) -> dict: continue if alias.func: - prop_value = alias.func(prop_value) + try: + prop_value = alias.func(prop_value) + except Exception as e: + self.logger.exception(e) + continue recipe_dict[alias.key] = prop_value diff --git a/mealie/services/migrations/paprika.py b/mealie/services/migrations/paprika.py index d0b64ac3859..3f92339afa1 100644 --- a/mealie/services/migrations/paprika.py +++ b/mealie/services/migrations/paprika.py @@ -38,7 +38,7 @@ def __init__(self, **kwargs): re_num_list = re.compile(r"^\d+\.\s") self.key_aliases = [ - MigrationAlias(key="recipeIngredient", alias="ingredients", func=lambda x: x.split("\n")), + MigrationAlias(key="recipeIngredient", alias="ingredients", func=lambda x: x.split("\n") if x else ""), MigrationAlias(key="orgURL", alias="source_url", func=None), MigrationAlias(key="totalTime", alias="total_time", func=None), MigrationAlias(key="prepTime", alias="prep_time", func=None), @@ -62,7 +62,7 @@ def __init__(self, **kwargs): MigrationAlias( key="recipeInstructions", alias="directions", - func=lambda x: [{"text": re.sub(re_num_list, "", s)} for s in x.split("\n\n")], + func=lambda x: [{"text": re.sub(re_num_list, "", s)} for s in x.split("\n\n")] if x else [], ), ]