Skip to content

Fix backup restore media rollback and log audits#66

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-57e2
Draft

Fix backup restore media rollback and log audits#66
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-57e2

Conversation

@cursor

@cursor cursor Bot commented Jun 18, 2026

Copy link
Copy Markdown

Bug and impact

  • Backup restore committed DB changes before replacing media files; if media copy failed, restored DB state could be left paired with deleted or partially restored media.
  • Log file download/delete used content_type_id=0, causing admin log IntegrityError; delete could remove the log file while reporting failure and recording no audit entry.
  • Backup restore/delete UI paths were mismatched or missing templates, blocking normal admin recovery/deletion flows.

Root cause

  • Media restore was performed after the DB transaction and destructively cleared MEDIA_ROOT before copy success was known.
  • Custom admin log entries used an invalid content type FK in log views.
  • Restore template submitted confirm_restore while the view required confirm, and delete referenced a missing confirmation template / GET link flow.

Fix

  • Stage backup media first, restore DB and replace media in one transaction block, and restore prior media on any failure.
  • Use nullable admin log content types for log file download/delete entries.
  • Align restore confirmation handling, add the backup delete confirmation template, and make the backup-list modal submit a CSRF-protected POST.

Validation

  • python manage.py test inventory.tests.test_views.BackupViewSecurityTest inventory.tests.test_views.LogFileViewTest
  • python manage.py test inventory.tests.test_sales_balance_payment inventory.tests.test_sale_status inventory.tests.test_services.MemberServiceTest
Open in Web View Automation 

Co-authored-by: Xianist Lab <zhtyyx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant