diff --git a/djcelery_transactions/transaction_signals.py b/djcelery_transactions/transaction_signals.py index d9b1c67..07553db 100644 --- a/djcelery_transactions/transaction_signals.py +++ b/djcelery_transactions/transaction_signals.py @@ -80,7 +80,7 @@ def leave_transaction_management(old_function, *args, **kwargs): def managed(old_function, *args, **kwargs): # Turning transaction management off causes the current transaction to be # committed if it's dirty. We must send the signal after the actual commit. - flag = kwargs.get('flag', args[0]) + flag = kwargs.get('flag', args[0] if args else None) if state is not None: using = kwargs.get('using', args[1] if len(args) > 1 else None) # Do not commit too early for prior versions of Django 1.3 diff --git a/tests/tests.py b/tests/tests.py index 04ea8ef..a0d01ca 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -47,3 +47,17 @@ def do_something(): self.assertFalse(my_global) else: self.fail('Exception not raised') + + def test_django_db_transaction_managed(self): + """ + Check that django.db.transaction.managed is not affected + by monkey-patching + """ + from django.db import transaction + self.assertFalse(transaction.is_managed()) + transaction.enter_transaction_management() + try: + transaction.managed() + self.assertTrue(transaction.is_managed()) + finally: + transaction.leave_transaction_management()