delete_users: only project models; Django admin history (LogEntry.user_id is staff) was being counted

Account deletion also keeps the status log of the payment records it keeps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-02 06:20:05 +03:30
parent 63cd1af6f7
commit 2f1e257533
3 changed files with 28 additions and 2 deletions

View File

@@ -63,3 +63,15 @@ class DeleteUsersTests(TestCase):
self.run_command('--ids', str(self.doomed.pk), str(self.kept.pk), '--yes', '--skip-paid')
self.assertTrue(User.objects.filter(pk=self.doomed.pk).exists())
self.assertFalse(User.objects.filter(pk=self.kept.pk).exists())
def test_django_admin_history_is_never_touched(self):
from django.contrib.admin.models import LogEntry
from django.contrib.auth.models import User as StaffUser
from accounts.management.commands.delete_users import user_scoped_models
self.assertNotIn(LogEntry, [model for model, _ in user_scoped_models()])
staff = StaffUser.objects.create(id=self.doomed.pk, username='staff')
LogEntry.objects.create(user=staff, action_flag=1, object_repr='x')
self.run_command('--ids', str(self.doomed.pk), '--yes')
self.assertEqual(LogEntry.objects.count(), 1)