Browse Source

Task.bin: Must not copy backend from app, task.backend is now instead a property. Closes #1821

Ask Solem 11 years ago
parent
commit
3dae6a7666
2 changed files with 23 additions and 1 deletions
  1. 13 1
      celery/app/task.py
  2. 10 0
      celery/task/base.py

+ 13 - 1
celery/app/task.py

@@ -343,6 +343,8 @@ class Task(object):
             'CELERY_STORE_ERRORS_EVEN_IF_IGNORED'),
     )
 
+    _backend = None  # set by backend property.
+
     __bound__ = False
 
     # - Tasks are lazily bound, so that configuration is not set
@@ -360,7 +362,6 @@ class Task(object):
                 setattr(self, attr_name, conf[config_name])
         if self.accept_magic_kwargs is None:
             self.accept_magic_kwargs = app.accept_magic_kwargs
-        self.backend = app.backend
 
         # decorate with annotations from config.
         if not was_bound:
@@ -899,6 +900,17 @@ class Task(object):
             self._exec_options = extract_exec_options(self)
         return self._exec_options
 
+    @property
+    def backend(self):
+        backend = self._backend
+        if backend is None:
+            return self.app.backend
+        return backend
+
+    @backend.setter
+    def backend(self, value):  # noqa
+        self._backend = value
+
     @property
     def __name__(self):
         return self.__class__.__name__

+ 10 - 0
celery/task/base.py

@@ -69,6 +69,16 @@ class Task(BaseTask):
     def request(cls):
         return cls._get_request()
 
+    @class_property
+    def backend(cls):
+        if cls._backend is None:
+            return cls.app.backend
+        return cls._backend
+
+    @backend.setter
+    def backend(cls, value):  # noqa
+        cls._backend = value
+
     @classmethod
     def get_logger(self, **kwargs):
         return get_task_logger(self.name)