make error_record resilient to None in 'using' arg (#33788)
This commit is contained in:
parent
c757033a56
commit
efd2da126f
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue