Browse Source

do not close cache connections for eager tasks

Ian Wilson 11 years ago
parent
commit
2877a5cc73
2 changed files with 4 additions and 9 deletions
  1. 1 7
      celery/fixups/django.py
  2. 3 2
      celery/tests/fixups/test_django.py

+ 1 - 7
celery/fixups/django.py

@@ -158,17 +158,11 @@ class DjangoFixup(object):
             self.close_database()
 
     def on_task_postrun(self, sender, **kwargs):
-        """Does everything necessary for Django to work in a long-living,
-        multiprocessing environment.
-
-        """
         # See http://groups.google.com/group/django-users/
         #            browse_thread/thread/78200863d0c07c6d/
-
-        # Do not close db connection for eager tasks.
         if not getattr(sender.request, 'is_eager', False):
             self.close_database()
-        self.close_cache()
+            self.close_cache()
 
     def close_database(self, **kwargs):
         if self._close_old_connections:

+ 3 - 2
celery/tests/fixups/test_django.py

@@ -149,12 +149,13 @@ class test_DjangoFixup(AppCase):
                     self.assertTrue(f.close_database.called)
                     self.assertTrue(f.close_cache.called)
 
-                # when a task is eager, do not close the db connection
+            # when a task is eager, do not close connections
+            with patch.object(f, 'close_cache'):
                 task.request.is_eager = True
                 with patch.object(f, 'close_database'):
                     f.on_task_postrun(task)
                     self.assertFalse(f.close_database.called)
-                    self.assertTrue(f.close_cache.called)
+                    self.assertFalse(f.close_cache.called)
 
     def test_close_database(self):
         with self.fixup_context(self.app) as (f, _, _):