Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make Nextcloud Migrations Fault Tolerant #3544

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading