Skip to content

fix: handle cascade delete when AccessAttemptExpiration table missing#1453

Open
muhamedfazalps wants to merge 1 commit into
jazzband:masterfrom
muhamedfazalps:fix/reset-attempts-graceful-cascade
Open

fix: handle cascade delete when AccessAttemptExpiration table missing#1453
muhamedfazalps wants to merge 1 commit into
jazzband:masterfrom
muhamedfazalps:fix/reset-attempts-graceful-cascade

Conversation

@muhamedfazalps

Copy link
Copy Markdown

Fixes #1389

Problem

Starting with django-axes 8.1.0, the AccessAttemptExpiration model was introduced. If an application does not apply the migration for this model, deleting AccessAttempt objects during a successful login triggers cascade deletion logic that attempts to delete a related AccessAttemptExpiration. Since the table does not exist, this results in an error.

Fix

Wrap the delete call in a try/except block. If the cascade delete fails (e.g., because the AccessAttemptExpiration table does not exist), log a warning and continue with remaining attempts instead of crashing.

Changes

  • axes/handlers/database.py: Added try/except around attempts.delete() in reset_user_attempts()

reset_user_attempts() calls attempts.delete() which triggers
cascade deletion of related AccessAttemptExpiration objects.
When the AccessAttemptExpiration migration has not been applied,
the table does not exist and the cascade delete raises an error.

Fix: wrap delete in try/except, log a warning, and continue.

Fixes jazzband#1389
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.

BUG: Error deleting AccessAttempt when AccessAttemptExpiration migration is not applied

1 participant