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

IntegrityError when deleting user who marked feedback as read #2408

Closed
timobrembeck opened this issue Sep 6, 2023 · 1 comment · Fixed by #2514
Closed

IntegrityError when deleting user who marked feedback as read #2408

timobrembeck opened this issue Sep 6, 2023 · 1 comment · Fixed by #2514
Assignees
Labels
🐛 bug Something isn't working ⁉️ prio: low Not urgent, can be resolved in the distant future. 😅 effort: medium Should be doable in <12h
Milestone

Comments

@timobrembeck
Copy link
Member

Describe the Bug

When a user is deleted who marked a specific feedback entry as read, an internal server error occurs.

Steps to Reproduce

  1. Login as user who is deleted later
  2. Mark feedback as read
  3. Login from admin account and delete that user
  4. See error

Expected Behavior

The user should be deleted, not sure what should happen to the feedback:

  • It could be marked unread again if SET_NULL is used
  • It could be deleted when CASCADE is used
  • We could also set the read_by field to another user, either a dummy user or an existing one in the region
  • We could define another field which denotes that the entry is read, but from a deleted user

Actual Behavior

An internal server error occurs:

django.db.utils.IntegrityError: update or delete on table "cms_user" violates foreign key constraint "cms_feedback_read_by_id_fbaaab26_fk_cms_user_id" on table "cms_feedback"
DETAIL:  Key (id)=(668) is still referenced from table "cms_feedback".

Additional Information

Traceback
Sep 05 09:27:58 ERROR   django.request - 500 Internal Server Error: /users/668/delete/
Traceback (most recent call last):
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
  return self.connection.commit()
psycopg2.errors.ForeignKeyViolation: update or delete on table "cms_user" violates foreign key constraint "cms_feedback_read_by_id_fbaaab26_fk_cms_user_id" on table "cms_feedback"
DETAIL:  Key (id)=(668) is still referenced from table "cms_feedback".

The above exception was the direct cause of the following exception:

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/users/user_actions.py", line 36, in delete_user
  user.delete()
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 967, in delete
  return collector.delete()
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/deletion.py", line 435, in delete
  signals.post_delete.send(
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/cacheops/transaction.py", line 77, in __exit__
  self._no_monkey.__exit__(self, exc_type, exc_value, traceback)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/transaction.py", line 246, in __exit__
  connection.commit()
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 33, in inner
  return func(*args, **kwargs)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 266, in commit
  self._commit()
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
  return self.connection.commit()
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
  raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
  return self.connection.commit()
django.db.utils.IntegrityError: update or delete on table "cms_user" violates foreign key constraint "cms_feedback_read_by_id_fbaaab26_fk_cms_user_id" on table "cms_feedback"
DETAIL:  Key (id)=(668) is still referenced from table "cms_feedback".
@timobrembeck timobrembeck added 🐛 bug Something isn't working ⁉️ prio: low Not urgent, can be resolved in the distant future. 😅 effort: medium Should be doable in <12h labels Sep 6, 2023
@timobrembeck timobrembeck added this to the 23Q4 milestone Sep 6, 2023
@seluianova
Copy link
Contributor

seluianova commented Oct 18, 2023

The issue is reproduced when:

  • the user was assigned to more than one region (z.B. A and B)
  • the user read a feedback in the region A
  • the user was removed from the region A (but remained in the region B)

Then, if we try to remove the user from region B (or in general, in "Network management"), the described error will occur.

The issue is not reproduced if the user was assigned to only one region. If so, cms_feedback_read_by_id is set to NULL, and the user is succesfully removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working ⁉️ prio: low Not urgent, can be resolved in the distant future. 😅 effort: medium Should be doable in <12h
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants