Skip to content

Commit

Permalink
Fixed #20028 -- Made atomic usable on callable instances.
Browse files Browse the repository at this point in the history
Thanks Anssi for the report.
  • Loading branch information
aaugustin committed Mar 12, 2013
1 parent 4846e2b commit 885d98d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/db/transaction.py
Expand Up @@ -17,6 +17,7 @@
from functools import wraps from functools import wraps


from django.db import connections, DatabaseError, DEFAULT_DB_ALIAS from django.db import connections, DatabaseError, DEFAULT_DB_ALIAS
from django.utils.decorators import available_attrs




class TransactionManagementError(Exception): class TransactionManagementError(Exception):
Expand Down Expand Up @@ -313,7 +314,7 @@ def __exit__(self, exc_type, exc_value, traceback):




def __call__(self, func): def __call__(self, func):
@wraps(func) @wraps(func, assigned=available_attrs(func))
def inner(*args, **kwargs): def inner(*args, **kwargs):
with self: with self:
return func(*args, **kwargs) return func(*args, **kwargs)
Expand Down
11 changes: 11 additions & 0 deletions tests/transactions/tests.py
Expand Up @@ -300,6 +300,17 @@ def test_atomic_prevents_calling_transaction_management_methods(self):
transaction.leave_transaction_management() 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): class IgnorePendingDeprecationWarningsMixin(object):


def setUp(self): def setUp(self):
Expand Down

0 comments on commit 885d98d

Please sign in to comment.