make error_record resilient to None in 'using' arg (#33788)

This commit is contained in:
Emmanuel Cazenave 2019-07-02 19:49:48 +02:00
parent c757033a56
commit efd2da126f
2 changed files with 14 additions and 4 deletions

View File

@ -70,6 +70,6 @@ def error_record(tag, tpl, **kwargs):
when logging in the middle of a transaction which is going to
rollback.
'''
return record(tag, tpl,
using=getattr(settings, 'JOURNAL_DB_FOR_ERROR_ALIAS', 'default'),
**kwargs)
if kwargs.get('using') is None:
kwargs['using'] = getattr(settings, 'JOURNAL_DB_FOR_ERROR_ALIAS', 'default')
return record(tag, tpl, **kwargs)

View File

@ -3,7 +3,7 @@ from django.contrib.auth.models import User, Group
from django.db import transaction
from django_journal import record
from django_journal import record, error_record
from django_journal.actions import export_as_csv_generator
from django_journal.models import Journal
@ -53,3 +53,13 @@ class JournalTestCase(TestCase):
l = list(export_as_csv_generator(qs))
self.assertEquals(l[1]['user'], '<deleted>')
def test_error_record(db):
error_record('error', 'error message')
journal = Journal.objects.first()
assert journal.tag.name == u'error'
assert journal.message == u'error message'
# specifying None as database use the defaut one
error_record('error', 'error message', using=None)
assert Journal.objects.count() == 2