Skip to content

Commit

Permalink
fix: Paprika Migration Error (#2834)
Browse files Browse the repository at this point in the history
* made migration more fault tolerant

* added edgecase for recipes with no ings/instructions

* keep log for debugging

---------

Co-authored-by: Kuchenpirat <[email protected]>
  • Loading branch information
michael-genson and Kuchenpirat authored Dec 13, 2023
1 parent 92d9551 commit 861e8ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion mealie/services/migrations/_migration_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions mealie/services/migrations/paprika.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 [],
),
]

Expand Down

0 comments on commit 861e8ac

Please sign in to comment.