From 885d98d24ac842708347c36644c61fc323c081ec Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Tue, 12 Mar 2013 10:52:16 +0100 Subject: [PATCH] Fixed #20028 -- Made atomic usable on callable instances. Thanks Anssi for the report. --- django/db/transaction.py | 3 ++- tests/transactions/tests.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/django/db/transaction.py b/django/db/transaction.py index 3a4c3f2b8d..1ff1a8437e 100644 --- a/django/db/transaction.py +++ b/django/db/transaction.py @@ -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) diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py index e5a608e583..e53a320481 100644 --- a/tests/transactions/tests.py +++ b/tests/transactions/tests.py @@ -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):