TransactionManagementError when writing database is not "default"
hmarty-ea opened this issue · comments
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(
...
Good catch @hmarty-ea! Would you happen to have the opportunity for opening a PR for fixing this?
@hmarty-ea this has been fixed in 6.1.1 by @hirotasoshu, thank you :)