Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20028 -- Made atomic usable on callable instances.

Thanks Anssi for the report.
  • Loading branch information...
commit 885d98d24ac842708347c36644c61fc323c081ec 1 parent 4846e2b
Aymeric Augustin authored
3  django/db/transaction.py
@@ -17,6 +17,7 @@
17 17
 from functools import wraps
18 18
 
19 19
 from django.db import connections, DatabaseError, DEFAULT_DB_ALIAS
  20
+from django.utils.decorators import available_attrs
20 21
 
21 22
 
22 23
 class TransactionManagementError(Exception):
@@ -313,7 +314,7 @@ def __exit__(self, exc_type, exc_value, traceback):
313 314
 
314 315
 
315 316
     def __call__(self, func):
316  
-        @wraps(func)
  317
+        @wraps(func, assigned=available_attrs(func))
317 318
         def inner(*args, **kwargs):
318 319
             with self:
319 320
                 return func(*args, **kwargs)
11  tests/transactions/tests.py
@@ -300,6 +300,17 @@ def test_atomic_prevents_calling_transaction_management_methods(self):
300 300
                 transaction.leave_transaction_management()
301 301
 
302 302
 
  303
+class AtomicMiscTests(TransactionTestCase):
  304
+
  305
+    def test_wrap_callable_instance(self):
  306
+        # Regression test for #20028
  307
+        class Callable(object):
  308
+            def __call__(self):
  309
+                pass
  310
+        # Must not raise an exception
  311
+        transaction.atomic(Callable())
  312
+
  313
+
303 314
 class IgnorePendingDeprecationWarningsMixin(object):
304 315
 
305 316
     def setUp(self):

0 notes on commit 885d98d

Please sign in to comment.
Something went wrong with that request. Please try again.