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

Deleting regions not possible if media library has nested structure #1749

Closed
timobrembeck opened this issue Oct 12, 2022 · 0 comments · Fixed by #1778
Closed

Deleting regions not possible if media library has nested structure #1749

timobrembeck opened this issue Oct 12, 2022 · 0 comments · Fixed by #1778
Assignees
Labels
🍼 good first issue Good for newcomers ‼️ prio: high Needs to be resolved ASAP. 🐛 bug Something isn't working ☺️ effort: low Should be doable in <4h
Milestone

Comments

@timobrembeck
Copy link
Member

Describe the Bug

Normally, media files and directories are cascade deleted when regions are deleted.
However, this fails if the protection rules between media files and directories prevent the cascade deletion.

Steps to Reproduce

  1. Create nested directory structure with media elements in subfolders
  2. Try to delete region
  3. See error

Expected Behavior

The region should be deleted and all media elements and directories with it.
This can either be achieved by deleting them in the correct order (by deleting the sub-folders and elements first) or removing the protected relationship by setting parent = None on all directories and parent_directory = None on all media files before deleting.

Actual Behavior

A ProtectedError occurs

Additional Information

Traceback
Oct 12 08:25:05 ERROR   django.request - 500 Internal Server Error: /regions/saarbrückenalt/delete/
Traceback (most recent call last):
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
  response = get_response(request)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
  response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/views/decorators/http.py", line 40, in inner
  return func(request, *args, **kwargs)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
  return view_func(request, *args, **kwargs)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/integreat_cms/cms/views/regions/region_actions.py", line 46, in delete_region
  deleted_objects = region.delete()
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 966, in delete
  collector.collect([self], keep_parents=keep_parents)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/deletion.py", line 302, in collect
  raise ProtectedError(
django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'Region' because they are referenced through protected foreign keys: 'Director
y.region'.", {<MediaFile (id: 66048, name: arriving.png, path: /var/www/integreat-cms/media/regions/252/2022/06/arriving.png, Landeshauptstadt Saarbrücken (alt)
(&#9888; Versteckt))>})
@timobrembeck timobrembeck added 🐛 bug Something isn't working 🍼 good first issue Good for newcomers ‼️ prio: high Needs to be resolved ASAP. ☺️ effort: low Should be doable in <4h labels Oct 12, 2022
@timobrembeck timobrembeck added this to the 22Q4 milestone Oct 12, 2022
@seluianova seluianova self-assigned this Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍼 good first issue Good for newcomers ‼️ prio: high Needs to be resolved ASAP. 🐛 bug Something isn't working ☺️ effort: low Should be doable in <4h
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants