Skip to content

Commit

Permalink
fix: Make Nextcloud Migrations Fault Tolerant (#3544)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-genson committed May 5, 2024
1 parent b0eece7 commit 6991dff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions mealie/schema/recipe/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def convert_extras_to_dict(cls, v):

return {x.key_name: x.value for x in v} if v else {}

@field_validator("nutrition", mode="before")
def validate_nutrition(cls, v):
return v or None

@classmethod
def loader_options(cls) -> list[LoaderOption]:
return [
Expand Down
2 changes: 1 addition & 1 deletion mealie/schema/recipe/recipe_nutrition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class Nutrition(MealieModel):
fiber_content: str | None = None
sodium_content: str | None = None
sugar_content: str | None = None
model_config = ConfigDict(from_attributes=True)
model_config = ConfigDict(from_attributes=True, coerce_numbers_to_str=True)
17 changes: 15 additions & 2 deletions mealie/services/migrations/nextcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from isodate.isoerror import ISO8601Error
from slugify import slugify

from mealie.schema.reports.reports import ReportEntryCreate

from ._migration_base import BaseMigrator
from .utils.migration_alias import MigrationAlias
from .utils.migration_helpers import MigrationReaders, glob_walker, import_image, split_by_comma
Expand Down Expand Up @@ -66,8 +68,19 @@ def _migrate(self) -> None:

all_recipes = []
for _, nc_dir in nextcloud_dirs.items():
recipe = self.clean_recipe_dictionary(nc_dir.recipe)
all_recipes.append(recipe)
try:
recipe = self.clean_recipe_dictionary(nc_dir.recipe)
all_recipes.append(recipe)
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 {nc_dir.name}",
exception=f"{e.__class__.__name__}: {e}",
)
)

all_statuses = self.import_recipes_to_database(all_recipes)

Expand Down

0 comments on commit 6991dff

Please sign in to comment.