fix: Make Nextcloud Migrations Fault Tolerant (#3544)

This commit is contained in:
Michael Genson 2024-05-05 06:17:29 -05:00 committed by GitHub
parent b0eece789d
commit 6991dff3e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View File

@ -243,6 +243,10 @@ class Recipe(RecipeSummary):
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 [

View File

@ -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)

View File

@ -9,6 +9,8 @@ import isodate
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
@ -66,8 +68,19 @@ class NextcloudMigrator(BaseMigrator):
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)