mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
added fault tolerance for malformed recipe json
This commit is contained in:
parent
b2e0c51ead
commit
f2e7deb5cb
@ -5,6 +5,7 @@ import zipfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from mealie.schema.recipe.recipe import Recipe
|
from mealie.schema.recipe.recipe import Recipe
|
||||||
|
from mealie.schema.reports.reports import ReportEntryCreate
|
||||||
|
|
||||||
from ._migration_base import BaseMigrator
|
from ._migration_base import BaseMigrator
|
||||||
from .utils.migration_alias import MigrationAlias
|
from .utils.migration_alias import MigrationAlias
|
||||||
@ -55,20 +56,28 @@ class MealieAlphaMigrator(BaseMigrator):
|
|||||||
zip_file.extractall(tmpdir)
|
zip_file.extractall(tmpdir)
|
||||||
|
|
||||||
temp_path = Path(tmpdir)
|
temp_path = Path(tmpdir)
|
||||||
|
|
||||||
recipe_lookup: dict[str, Path] = {}
|
recipe_lookup: dict[str, Path] = {}
|
||||||
recipes_as_dicts = []
|
|
||||||
|
|
||||||
for x in temp_path.rglob("**/recipes/**/[!.]*.json"):
|
recipes: list[Recipe] = []
|
||||||
if (y := MigrationReaders.json(x)) is not None:
|
for recipe_json_path in temp_path.rglob("**/recipes/**/[!.]*.json"):
|
||||||
recipes_as_dicts.append(y)
|
try:
|
||||||
slug = y["slug"]
|
if (recipe_as_dict := MigrationReaders.json(recipe_json_path)) is not None:
|
||||||
recipe_lookup[slug] = x.parent
|
recipe = self._convert_to_new_schema(recipe_as_dict)
|
||||||
|
recipes.append(recipe)
|
||||||
recipes = [self._convert_to_new_schema(x) for x in recipes_as_dicts]
|
slug = recipe_as_dict["slug"]
|
||||||
|
recipe_lookup[slug] = recipe_json_path.parent
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.exception(e)
|
||||||
|
self.report_entries.append(
|
||||||
|
ReportEntryCreate(
|
||||||
|
report_id=self.report_id,
|
||||||
|
success=False,
|
||||||
|
message=f"Failed to import {recipe_json_path.name}",
|
||||||
|
exception=f"{e.__class__.__name__}: {e}",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
results = self.import_recipes_to_database(recipes)
|
results = self.import_recipes_to_database(recipes)
|
||||||
|
|
||||||
for slug, recipe_id, status in results:
|
for slug, recipe_id, status in results:
|
||||||
if not status:
|
if not status:
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user