From 783459b08484c63a95efd4f4b3c05d72759d817e Mon Sep 17 00:00:00 2001 From: Nicolas Grasset Date: Fri, 31 Oct 2014 13:01:40 -0400 Subject: [PATCH] Fixed the tests for 1.6, CELERY_EAGER now working differently --- djcelery_transactions/__init__.py | 2 +- djcelery_transactions/transaction_signals.py | 8 ++++---- tests/tests.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/djcelery_transactions/__init__.py b/djcelery_transactions/__init__.py index c15d955..4ffea01 100644 --- a/djcelery_transactions/__init__.py +++ b/djcelery_transactions/__init__.py @@ -55,7 +55,7 @@ def apply_async(self, *args, **kwargs): # Delay the task unless the client requested otherwise or transactions # aren't being managed (i.e. the signal handlers won't send the task). connection = get_connection() - if connection.in_atomic_block and not getattr(current_app.conf, 'CELERY_ALWAYS_EAGER', False): + if connection.in_atomic_block: _get_task_queue().append((self, args, kwargs)) else: return self.original_apply_async(*args, **kwargs) diff --git a/djcelery_transactions/transaction_signals.py b/djcelery_transactions/transaction_signals.py index 4c2c41d..5881f83 100644 --- a/djcelery_transactions/transaction_signals.py +++ b/djcelery_transactions/transaction_signals.py @@ -160,7 +160,7 @@ def __patched__exit__(self, exc_type, exc_value, traceback): try: connection.savepoint_rollback(sid) transaction.signals.post_rollback.send(None) - except Error: + except Exception: # If rolling back to a savepoint fails, mark for # rollback at a higher level and avoid shadowing # the original exception. @@ -175,7 +175,7 @@ def __patched__exit__(self, exc_type, exc_value, traceback): try: connection.rollback() transaction.signals.post_rollback.send(None) - except Error: + except Exception: # An error during rollback means that something # went wrong with the connection. Drop it. connection.close() @@ -193,7 +193,7 @@ def __patched__exit__(self, exc_type, exc_value, traceback): try: connection.savepoint_rollback(sid) transaction.signals.post_rollback.send(None) - except Error: + except Exception: # If rolling back to a savepoint fails, mark for # rollback at a higher level and avoid shadowing # the original exception. @@ -203,7 +203,7 @@ def __patched__exit__(self, exc_type, exc_value, traceback): try: connection.rollback() transaction.signals.post_rollback.send(None) - except Error: + except Exception: # An error during rollback means that something # went wrong with the connection. Drop it. connection.close() diff --git a/tests/tests.py b/tests/tests.py index e3de00e..530d84e 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,6 +1,6 @@ from djcelery_transactions import task -from django.db import transaction +from django.db.transaction import atomic from django.test import TransactionTestCase my_global = [] @@ -31,7 +31,7 @@ def test_commited_transaction_fire_task(self): """Check that task is consumed when no exception happens """ - @transaction.commit_on_success + @atomic() def do_something(): my_task.delay() @@ -42,7 +42,7 @@ def test_rollbacked_transaction_discard_task(self): """Check that task is not consumed when exception happens """ - @transaction.commit_on_success + @atomic() def do_something(): my_task.delay() raise SpecificException