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

[BUG] - Unable to Delete Food If It Appears On A Shopping List Item #2893

Closed
5 of 6 tasks
michael-genson opened this issue Dec 31, 2023 · 2 comments
Closed
5 of 6 tasks
Labels
bug Something isn't working stale triage

Comments

@michael-genson
Copy link
Collaborator

michael-genson commented Dec 31, 2023

First Check

  • This is not a feature request.
  • I added a very descriptive title to this issue (title field is above this).
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Mealie documentation, with the integrated search.
  • I already read the docs and didn't find an answer.
  • This issue can be replicated on the demo site (https://demo.mealie.io/).

What is the issue you are experiencing?

When trying to delete a food that is being used on a shopping list, an error is thrown. Peeking into the error message, I see:

{
  "detail": {
    "message": "An unexpected error occurred",
    "error": true,
    "exception": "(psycopg2.errors.ForeignKeyViolation) update or delete on table \"ingredient_foods\" violates foreign key constraint \"shopping_list_items_food_id_fkey\" on table \"shopping_list_items\"\nDETAIL:  Key (id)=(3927a452-da8b-4c24-bd2d-d463433b84c4) is still referenced from table \"shopping_list_items\".\n\n[SQL: DELETE FROM ingredient_foods WHERE ingredient_foods.id = %(id)s::UUID]\n[parameters: {'id': '3927a452-da8b-4c24-bd2d-d463433b84c4'}]\n(Background on this error at: https://sqlalche.me/e/20/gkpj)"
  }
}

Steps to Reproduce

  1. Create a food
  2. Add the food to a shopping list item
  3. Attempt to delete the food (e.g. from the Data Management page)

Please provide relevant logs

See above

Mealie Version

Nightly

Deployment

Docker (Synology)

Additional Deployment Details

Using postgres. Couldn't reproduce this on nightly, so it might be DB specific

@michael-genson michael-genson added bug Something isn't working triage labels Dec 31, 2023
@boc-the-git
Copy link
Collaborator

Based on something I experienced in the unit tests for this PR, I think SQLite might not be great at enforcing foreign keys. Possibly it doesn't take notice of them at all.

I don't have a Postgres instance handy to actually 'confirm' this bug, but from just reading the title my immediate thought was "that's a foreign key constraint".

I am curious what the actual impact of SQLite not catching this issue is..

A solution might be to implement at the time of deletion a check on various places (e.g. shopping list) that an entity can be referenced. Feels like some overhead though. 🤔

Copy link
Contributor

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.

@github-actions github-actions bot added the stale label Feb 13, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale triage
Projects
None yet
Development

No branches or pull requests

2 participants