TransactionManagementError when writing database is not "default"
hmarty-ea opened this issue · comments
hmarty-ea commented
When starting atomic transactions in AxesDatabaseHandler
, the database is not specified. This can cause a TransactionManagementError
if the writing database is not the default one after select_for_update()
is called.
The solution would be to call db.router.db_for_write()
to get the database name:
with transaction.atomic(using=db.router.db_for_write(AccessAttempt)):
(
attempt,
created,
) = AccessAttempt.objects.select_for_update().get_or_create(
...
Aleksi Häkli commented
Good catch @hmarty-ea! Would you happen to have the opportunity for opening a PR for fixing this?
Aleksi Häkli commented
@hmarty-ea this has been fixed in 6.1.1 by @hirotasoshu, thank you :)