From 4861f3c988e16bd39c9a59c19d978ec7241a80ec Mon Sep 17 00:00:00 2001 From: Maksim Zayakin Date: Thu, 31 Aug 2023 22:42:44 +0500 Subject: [PATCH] fix: fix TransactionManagementError --- axes/handlers/database.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/axes/handlers/database.py b/axes/handlers/database.py index 035cc60..95678b2 100644 --- a/axes/handlers/database.py +++ b/axes/handlers/database.py @@ -1,8 +1,8 @@ from logging import getLogger from typing import Optional -from django.db import transaction -from django.db.models import F, Sum, Value, Q +from django.db import router, transaction +from django.db.models import F, Q, Sum, Value from django.db.models.functions import Concat from django.utils import timezone @@ -171,7 +171,7 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler): "AXES: Username is None and username is the only one lockout parameter, new record will NOT be created." ) else: - with transaction.atomic(): + with transaction.atomic(using=router.db_for_write(AccessAttempt)): ( attempt, created, @@ -243,7 +243,7 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler): # 5. database entry: Log for ever the attempt in the AccessFailureLog if settings.AXES_ENABLE_ACCESS_FAILURE_LOG: - with transaction.atomic(): + with transaction.atomic(using=router.db_for_write(AccessFailureLog)): AccessFailureLog.objects.create( username=username, ip_address=request.axes_ip_address,