Repository: jazzband/django-axes
Pull request #1298 (2025-04-04 12:54:26)

chore(deps): bump pytest-django from 4.10.0 to 4.11.1
Bumps [pytest-django](https://github.com/pytest-dev/pytest-django) from 4.10.0 to 4.11.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/pytest-dev/pytest-django/releases">pytest-django's releases</a>.</em></p>
<blockquote>
<h2>v4.11.1</h2>
<p><a href="https://github.com/pytest-dev/pytest-django/blob/main/docs/changelog.rst#v4111-2025-04-03">https://github.com/pytest-dev/pytest-django/blob/main/docs/changelog.rst#v4111-2025-04-03</a></p>
<h2>v4.11.0</h2>
<p><a href="https://github.com/pytest-dev/pytest-django/blob/main/docs/changelog.rst#v4110-2025-04-01">https://github.com/pytest-dev/pytest-django/blob/main/docs/changelog.rst#v4110-2025-04-01</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/pytest-dev/pytest-django/blob/main/docs/changelog.rst">pytest-django's changelog</a>.</em></p>
<blockquote>
<h2>v4.11.1 (2025-04-03)</h2>
<p>Bugfixes
^^^^^^^^</p>
<ul>
<li>Fixed a regression in v4.11.0 for Django <code>TestCase</code> tests using the <code>databases</code> class variable (<code>[#1188](https://github.com/pytest-dev/pytest-django/issues/1188) &lt;https://github.com/pytest-dev/pytest-django/issues/1188&gt;</code>__).</li>
</ul>
<h2>v4.11.0 (2025-04-01)</h2>
<p>Compatibility
^^^^^^^^^^^^^</p>
<ul>
<li>Added official support for Django 5.2 (<code>PR [#1179](https://github.com/pytest-dev/pytest-django/issues/1179) &lt;https://github.com/pytest-dev/pytest-django/pull/1179&gt;</code>__).</li>
<li>Dropped testing on MySQL’s MyISAM storage engine (<code>PR [#1180](https://github.com/pytest-dev/pytest-django/issues/1180) &lt;https://github.com/pytest-dev/pytest-django/pull/1180&gt;</code>__).</li>
</ul>
<p>Bugfixes
^^^^^^^^</p>
<ul>
<li>
<p>Stopped setting up and serializing databases on test session setup when not needed (the database is not requested / <code>serialized_rollback</code> is not used).
On test databases with large amounts of pre-seeded data, this may remove a delay of a few seconds when running <code>pytest --reuse-db</code>.</p>
<p>The determination of which databases to setup is done by static inspection of the test suite.
Using pytest's dynamic features to request db access, such as :meth:<code>request.getfixturevalue(&quot;db&quot;) &lt;pytest.FixtureRequest.getfixturevalue&gt;</code>, may throw off this analysis.
If you start seeing <code>DatabaseOperationForbidden</code> or &quot;unable to open database&quot; errors, this is likely the cause.
To fix this, decorate at least one test with the :func:<code>django_db &lt;pytest.mark.django_db&gt;</code> marker with appropriate <code>databases</code> and <code>serialized_rollback</code> settings.</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/5ada9c1596ee9e0624801d553995d98d2e3ccce8"><code>5ada9c1</code></a> Release 4.11.1</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/cf3f0bb89be0d741e7c4e10469d0559e86753cc7"><code>cf3f0bb</code></a> fixtures: fixup a regression in previous release for TestCase multi-db support</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/6d5c272519037031f0b68d78dca44727b860d65e"><code>6d5c272</code></a> Release 4.11.0</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/8000db04f07822861331d0df8ef52f9c67eafc00"><code>8000db0</code></a> Only setup and serialize databases as needed by tests</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/6f7fc269f871da0134d9155ca856b29582aa46ce"><code>6f7fc26</code></a> Add optional integration of pytest into django's <code>manage.py test</code></li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/3071a666dce1f60299bf89bd9c268ac7e0ee459d"><code>3071a66</code></a> docs/conf.py: format with ruff format</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/3f44e50ff326c23a44bf5633423d491a251d8eed"><code>3f44e50</code></a> fixtures: avoid unnecessary closure</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/b7328696ad7a5bfc308b60c909972a9166fce8a3"><code>b732869</code></a> Remove testing on MyISAM (<a href="https://redirect.github.com/pytest-dev/pytest-django/issues/1180">#1180</a>)</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/e362f4c6303b203e5449ed023b353ad81f40a753"><code>e362f4c</code></a> Add support for Django 5.2 (<a href="https://redirect.github.com/pytest-dev/pytest-django/issues/1179">#1179</a>)</li>
<li>See full diff in <a href="https://github.com/pytest-dev/pytest-django/compare/v4.10.0...v4.11.1">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pytest-django&package-manager=pip&previous-version=4.10.0&new-version=4.11.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

aleksihakli: @dependabot rebase
dependabot[bot]: Looks like this PR is already up-to-date with master! If you'd still like to recreate it from scratch, overwriting any edits, you can request `@dependabot recreate`.

Patch:
diff --git a/axes/handlers/database.py b/axes/handlers/database.py
index c8e119d..9effa77 100644
--- a/axes/handlers/database.py
+++ b/axes/handlers/database.py
@@ -117,10 +117,10 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
         return attempt_count
 
     def user_login_failed(self, sender, credentials: dict, request=None, **kwargs):
-        """When user login fails, save AccessFailureLog record in database,
+        """
+        When user login fails, save AccessFailureLog record in database,
         save AccessAttempt record in database, mark request with
         lockout attribute and emit lockout signal.
-
         """
 
         log.info("AXES: User login failed, running database handler for failure.")
@@ -261,9 +261,6 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
         When user logs in, update the AccessLog related to the user.
         """
 
-        # 1. database query: Clean up expired user attempts from the database
-        clean_expired_user_attempts(request, credentials)
-
         username = user.get_username()
         credentials = get_credentials(username)
         client_str = get_client_str(
@@ -276,6 +273,9 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
 
         log.info("AXES: Successful login by %s.", client_str)
 
+        # 1. database query: Clean up expired user attempts from the database
+        clean_expired_user_attempts(request, credentials)
+
         if not settings.AXES_DISABLE_ACCESS_LOG:
             # 2. database query: Insert new access logs with login time
             AccessLog.objects.create(
@@ -304,10 +304,8 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
         When user logs out, update the AccessLog related to the user.
         """
 
-        # 1. database query: Clean up expired user attempts from the database
-        clean_expired_user_attempts(request)
-
         username = user.get_username() if user else None
+        credentials = get_credentials(username) if username else None
         client_str = get_client_str(
             username,
             request.axes_ip_address,
@@ -316,6 +314,9 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
             request,
         )
 
+        # 1. database query: Clean up expired user attempts from the database
+        clean_expired_user_attempts(request, credentials)
+
         log.info("AXES: Successful logout by %s.", client_str)
 
         if username and not settings.AXES_DISABLE_ACCESS_LOG:


Test patch:
diff --git a/requirements-test.txt b/requirements-test.txt
index 867c416..cf821bd 100644
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -3,5 +3,5 @@ django-ipware>=3
 coverage==7.8.0
 pytest==8.3.4
 pytest-cov==6.1.1
-pytest-django==4.10.0
+pytest-django==4.11.1
 pytest-subtests==0.14.1