diff --git a/easyaudit/signals/auth_signals.py b/easyaudit/signals/auth_signals.py index fbe2b16a..fa626a77 100644 --- a/easyaudit/signals/auth_signals.py +++ b/easyaudit/signals/auth_signals.py @@ -4,14 +4,15 @@ from easyaudit.middleware.easyaudit import get_current_request from easyaudit.models import LoginEvent -from easyaudit.settings import REMOTE_ADDR_HEADER, WATCH_AUTH_EVENTS, LOGGING_BACKEND +from easyaudit.settings import REMOTE_ADDR_HEADER, WATCH_AUTH_EVENTS, LOGGING_BACKEND, \ + DATABASE_ALIAS audit_logger = import_string(LOGGING_BACKEND)() def user_logged_in(sender, request, user, **kwargs): try: - with transaction.atomic(): + with transaction.atomic(using=DATABASE_ALIAS): login_event = audit_logger.login({ 'login_type': LoginEvent.LOGIN, 'username': getattr(user, user.USERNAME_FIELD), @@ -24,7 +25,7 @@ def user_logged_in(sender, request, user, **kwargs): def user_logged_out(sender, request, user, **kwargs): try: - with transaction.atomic(): + with transaction.atomic(using=DATABASE_ALIAS): login_event = audit_logger.login({ 'login_type': LoginEvent.LOGOUT, 'username': getattr(user, user.USERNAME_FIELD), @@ -37,7 +38,7 @@ def user_logged_out(sender, request, user, **kwargs): def user_login_failed(sender, credentials, **kwargs): try: - with transaction.atomic(): + with transaction.atomic(using=DATABASE_ALIAS): request = get_current_request() # request argument not available in django < 1.11 user_model = get_user_model() login_event = audit_logger.login({