Skip to content

BUG: Error deleting AccessAttempt when AccessAttemptExpiration migration is not applied #1389

@AndreasActuals

Description

@AndreasActuals

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

To Reproduce
Steps to reproduce the behavior:

  1. Install django-axes ≥ 8.1.0.
  2. Do not apply the AccessAttemptExpiration migration.
  3. Make a failed login attempt (creates an AccessAttempt).
  4. Perform a successful login.
  5. reset_user_attempts() deletes AccessAttempt and attempts to cascade-delete AccessAttemptExpiration, which does not exist.

Expected behavior
When AccessAttemptExpiration is not used and its migration is not applied, deleting AccessAttempt records should not attempt to access or delete AccessAttemptExpiration, and successful logins should reset attempts without errors.

Your environment
python version: 3.13
django version: 6.0.1
django-axes version: 8.1.0
Operating system: Windows

Additional context
AccessAttemptExpiration is defined as a OneToOneField with on_delete=models.CASCADE. The current reset logic does not guard against the absence of related expiration objects, causing a regression for applications that do not use the new feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions