mealie-recipes / mealie

Mealie is a self hosted recipe manager and meal planner with a RestAPI backend and a reactive frontend application built in Vue for a pleasant user experience for the whole family. Easily add recipes into your database by providing the url and mealie will automatically import the relevant data or add a family recipe with the UI editor
https://docs.mealie.io
GNU Affero General Public License v3.0
7.52k stars 754 forks source link

[BUG] - Removing a recipe ingredient doesn't remove its links to steps #3956

Open YodaDaCoda opened 4 months ago

YodaDaCoda commented 4 months ago

First Check

What is the issue you are experiencing?

When a recipe ingredient is removed from the recipe, any recipe-step links for that ingredient are not removed from the steps.

Steps to Reproduce

  1. Create a new recipe or edit an existing one
  2. Link an ingredient to a step
  3. Remove the ingredient from the recipe
  4. Open the ingredient's JSON and observe that there exists an ingredientReferences on the step without a corresponding recipeIngredient.

Please provide relevant logs

N/A

Mealie Version

v1.10.2

Deployment

Docker (Linux)

Additional Deployment Details

No response

YodaDaCoda commented 4 months ago

I discovered this when the Mealient app for Android wouldn't display one of my recipes after editing it. While I do think Mealient should handle this situation more gracefully, Mealie should avoid this in the first place.

kirmanak/Mealient#284

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

YodaDaCoda commented 3 months ago

Can this be re-opened?

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

YodaDaCoda commented 2 months ago

I tried to figure out how to do this some weeks ago but couldn't see a clear path where I might make changes. Happy to try again with some direction?

michael-genson commented 2 months ago

You'll probably want to add a check in the recipe service upon updating to remove any ingredient links for non-existent ingredients:

https://github.com/mealie-recipes/mealie/blob/mealie-next/mealie/services/recipe/recipe_service.py

shethshlok commented 2 weeks ago

Hey @michael-genson, can I work on this issue?

michael-genson commented 2 weeks ago

@shethshlok for sure! Generally anyone is welcome to work on any issue

shethshlok commented 1 week ago

Thanks @michael-genson, I had a question for you, I added a function in the recipe_service.py that checks for invalid reference ids in instructions and removes them from db, although I have to manually refresh the page to see the changes, considering this I also have to make changes to the fronted too? Updating the state?

michael-genson commented 1 week ago

I would have to see the context to answer that question, I would recommend opening a PR with your solution.

Generally we shouldn't be implementing cleanup solutions and instead should fix the service so it doesn't create bad data, then running a one-time database fix to clean up the existing bad data.