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

Feature: Migrate from Tandoor #2438

Merged

Conversation

michael-genson
Copy link
Collaborator

What type of PR is this?

(REQUIRED)

  • cleanup
  • feature

What this PR does / why we need it:

(REQUIRED)

Adds support for Tandoor migrations (see #2427). Also refactors the display property implemented in #2021 to apply to the RecipeIngredient class.

Which issue(s) this PR fixes:

(REQUIRED)

N/A - discussed in #2427. The actual issue in that discussion is fixed by #2434

Special notes for your reviewer:

(fill-in or delete this section)

Since Tandoor provides structured data similar to Mealie (food, unit, qty) I needed to reuse the display property implemented in #2021. To make it easier to reuse I refactored all ingredient-like objects to use a new RecipeIngredientBase class which contains the display parsing logic.

To do this, I had to add the disable_amount and is_food to the base, which are effectively the same thing (but ingredients use disable_amount and shopping lists use is_food). There's probably room to simplify this, but it would involve removing one of the fields which would require refactoring either recipes or shopping lists, which is outside the scope of this PR (honestly this refactor is too, but that would be even more out of scope...). I also noticed that the recipe's disable_amount setting doesn't propagate down to its ingredients, so I overrode the Recipe __init__ and from_orm to populate it correctly based on the recipe's settings (and shopping list items use is_food so no changes were needed there):

...
@classmethod
def from_orm(cls, obj):
    recipe = super().from_orm(obj)
    recipe.__post_init__()
    return recipe

def __init__(self, **kwargs) -> None:
    super().__init__(**kwargs)
    self.__post_init__()

def __post_init__(self) -> None:
    # the ingredient disable_amount property is unreliable,
    # so we set it here and recalculate the display property
    disable_amount = self.settings.disable_amount if self.settings else True
    for ingredient in self.recipe_ingredient:
        ingredient.disable_amount = disable_amount
        ingredient.is_food = not ingredient.disable_amount
        ingredient.display = ingredient._format_display()

Testing

(fill-in or delete this section)

Imported the sample 500 or so recipes from #2427 and they look pretty good (see some example screenshots there). Manually checked a dozen or so, including some edge cases (e.g. missing data). 100% of those recipes imported with no errors. I also added sample data to the migration tests.

Release Notes

(REQUIRED)

added support for Tandoor migrations

@hay-kot hay-kot merged commit 0f89610 into mealie-recipes:mealie-next Jul 23, 2023
@hay-kot
Copy link
Collaborator

hay-kot commented Jul 23, 2023

So. Good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants