mirror of https://github.com/django/django.git
Fixed #20028 -- Made atomic usable on callable instances.
Thanks Anssi for the report.
This commit is contained in:
parent
4846e2b744
commit
885d98d24a
|
@ -17,6 +17,7 @@ import warnings
|
|||
from functools import wraps
|
||||
|
||||
from django.db import connections, DatabaseError, DEFAULT_DB_ALIAS
|
||||
from django.utils.decorators import available_attrs
|
||||
|
||||
|
||||
class TransactionManagementError(Exception):
|
||||
|
@ -313,7 +314,7 @@ class Atomic(object):
|
|||
|
||||
|
||||
def __call__(self, func):
|
||||
@wraps(func)
|
||||
@wraps(func, assigned=available_attrs(func))
|
||||
def inner(*args, **kwargs):
|
||||
with self:
|
||||
return func(*args, **kwargs)
|
||||
|
|
|
@ -300,6 +300,17 @@ class AtomicErrorsTests(TransactionTestCase):
|
|||
transaction.leave_transaction_management()
|
||||
|
||||
|
||||
class AtomicMiscTests(TransactionTestCase):
|
||||
|
||||
def test_wrap_callable_instance(self):
|
||||
# Regression test for #20028
|
||||
class Callable(object):
|
||||
def __call__(self):
|
||||
pass
|
||||
# Must not raise an exception
|
||||
transaction.atomic(Callable())
|
||||
|
||||
|
||||
class IgnorePendingDeprecationWarningsMixin(object):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue