Skip to content

43697 backend [ Command panel ] Error 500 when deleting an account or user#175

Merged
pneumojoseph merged 8 commits into
masterfrom
backend/admin/43697__error_when_deleting_user
Mar 18, 2026
Merged

43697 backend [ Command panel ] Error 500 when deleting an account or user#175
pneumojoseph merged 8 commits into
masterfrom
backend/admin/43697__error_when_deleting_user

Conversation

@EBirkenfeld
Copy link
Copy Markdown
Collaborator

@EBirkenfeld EBirkenfeld commented Mar 16, 2026

1. Description (problem)

  • Issue: A 500 error occurred when deleting an [Account] or a [User] through the Django administrative panel.
  • Root Cause: The existence of "corrupted" [Notification] objects with text=None (NULL) in the database caused a crash when Django Admin prepared the deletion confirmation page (likely during string representation of related objects).
  • Location: Manifested in Django Admin (/admin/) on the deletion confirmation pages for accounts and users.

2. Context

  • This task aims to improve the stability of administrative data cleanup procedures.

3. Solution

  • Updated the Notification.text field to include default='' and removed null=True. The field is now strictly a string at both the database and model levels.
  • Created a migration to apply these changes.
  • Updated existing tests in [test_send_urgent.py] that previously relied on checking for text=None.

4. Implementation Details

  • Affected Files:
    • [backend/src/accounts/models.py]: Updated the [Notification] model.
    • [backend/src/accounts/migrations/0140_notification_text_default.py]: New migration file.
    • [backend/src/notifications/tests/test_tasks/test_send_urgent.py]: Fixed query conditions in tests (checking for empty string instead of NULL).
  • Testing: Added a new end-to-end test file [backend/src/accounts/tests/test_admin.py] specifically for Admin UI verification.

5. What to Test

5.1 Preconditions

  • Deployed development environment.
  • Superuser access to the Django Admin panel.

5.2 Positive Scenarios

  1. Delete account with an empty notification:
    • Create an account and a user.
    • Manually (via shell) create a notification for this user with text='' (empty string).
    • Navigate to the Account list in Admin, select the account, and click "Delete".
    • Expected result: The deletion confirmation page opens without a 500 error, displaying the list of related objects.
  2. Delete user with an empty notification:
    • Follow the same steps as Scenario 1, but initiate deletion from the User list in Admin.
    • Expected result: The deletion confirmation page is displayed successfully.

5.3 Negative Scenarios and Edge Cases

  • Legacy notifications (NULL in DB):
    • Ensure that existing NULL values in the [text] field are correctly converted to empty strings during migration.
  • Creating a new notification:
    • Create a notification via API/code without providing the [text] value.
    • Expected result: Notification is created successfully with an empty string in the [text] field.

5.4 Verification Points

  • Verify in the DB that no [Notification] has a NULL value in the [text] field.
  • Server logs should not contain TypeError or similar errors when opening Admin deletion pages.

5.6 What Was NOT Tested

  • Deletion via API (tested via Django Admin only).
  • Mobile devices.
  • Locales were not tested (no changes to translations).

6. Testing Affected Areas

  • The change affects the [Notification] model used throughout the system. It is crucial to ensure that notification creation via Celery tasks (Overdue, Mentions, etc.) remains functional. Core notification tests (e.g., [test_send_overdue_task_notification.py]) were executed.

8. Commits

  • fix(accounts): prevent 500 error on delete account/user with empty notifications

9. Release notes:

  • Fixed a 500 error in the Admin panel when deleting accounts or users with empty notifications.

Note

Medium Risk
Includes a data migration that updates existing accounts_notification.text NULLs and changes the model field semantics from None to '', which may affect any code paths that relied on NULL/None checks.

Overview
Prevents Django Admin 500s during account/user deletion by making Notification.text consistently a string: a new migration backfills existing NULL accounts_notification.text values to '' and alters the field to default='' (removing null=True).

Updates urgent-notification task tests to assert text='' instead of None when querying/validating created notifications.

Written by Cursor Bugbot for commit 8fc34b6. This will update automatically on new commits. Configure here.

Note

Fix Error 500 when deleting an account or user by making Notification.text non-nullable

Changes the text field on the Notification model from null=True to default='' to prevent null values that caused 500 errors during account/user deletion. A database migration updates existing NULL rows to empty strings before altering the column. Tests are updated to assert text='' instead of text=None.

Macroscope summarized 8fc34b6.

Comment thread backend/src/accounts/migrations/0141_notification_text_default.py
@EBirkenfeld EBirkenfeld added the Backend API changes request label Mar 16, 2026
pneumojoseph
pneumojoseph previously approved these changes Mar 17, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread backend/src/accounts/models.py
Maria-Lordwill
Maria-Lordwill previously approved these changes Mar 18, 2026
@EBirkenfeld EBirkenfeld dismissed stale reviews from pneumojoseph and Maria-Lordwill via 8fc34b6 March 18, 2026 12:05
@pneumojoseph pneumojoseph merged commit abf2298 into master Mar 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend API changes request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants