TandoorRecipes / recipes

Application for managing recipes, planning meals, building shopping lists and much much more!
https://docs.tandoor.dev
Other
5.13k stars 547 forks source link

Unable to Delete a Property Type #3163

Closed RaftisGIS closed 1 month ago

RaftisGIS commented 1 month ago

Tandoor Version

1.5.17

Setup

Docker / Docker-Compose

Reverse Proxy

SWAG

Other

No response

Bug description

I added a new property type named sodium and added it to a recipe with a value of 500 mg. I decided this isn't how I wanted to track sodium in recipes so I removed the property from the recipe. I then tried to delete the property itself from the property type page using the three dots menu for the sodium entry. I then get the pop up "Failure - There was an error deleting a resource!". I think I pulled the relevant parts from the logs, but let me know if I missed important information.

Relevant logs

Traceback (most recent call last):
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/mixins.py", line 91, in destroy
    self.perform_destroy(instance)
  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/mixins.py", line 95, in perform_destroy
    instance.delete()
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1131, in delete
    collector.collect([self], keep_parents=keep_parents)
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/deletion.py", line 355, in collect
    raise ProtectedError(
django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'PropertyType' because they are referenced through protected foreign keys: 'Property.property_type'.", {<Property: 500.0000 mg Sodium>, <Property: 500.0000 mg Sodium>})
smilerz commented 1 month ago

go to /admin/cookbook/property/ and delete the property first.

RaftisGIS commented 1 month ago

Sweet that did it, thanks for your help! I figured there had to be a way to interact with the underlying database but couldn't figure it out myself.

vabene1111 commented 1 month ago

On the new frontend I will add a page to manage property types