فهرست منبع

Fix results for cassandra backend in detailed mode

When using the Cassandra backend in detailed mode, attempting to
retrieve the results results in an error because of improperly
decoded metadata (introduced by
6d64d7a24f15311a0bd13baf7f6a9879176d2d08).

The metadata for `children` and `traceback` are encoded before being
grouped into the dictionary, which itself is encoded later prior to
being stored in Cassandra. During retrieval in detailed mode, these
are not decoded again, causing them to be interpreted as encoded
unicode literals instead of their native types.

CHANGES:
- the `results` metadata is encoded regardless of whether Cassandra is
  used in detailed or non-detailed mode. This is being consistent with
  the other backends where the results are always encoded. It may be
  unnecessary (results in double encoding), however.

- The logic for encoding/decoding metadata is now consistent for both
  detailed and non-detailed modes.

REFERENCE:
- 21cdf82fc4310320c21687cf80a3f98802565bd5 - cassandra detailed mode
- 6d64d7a24f15311a0bd13baf7f6a9879176d2d08 - backends support children

Conflicts:
	celery/backends/cassandra.py
Gino Ledesma 10 سال پیش
والد
کامیت
7a14d6f1a1
1فایلهای تغییر یافته به همراه5 افزوده شده و 8 حذف شده
  1. 5 8
      celery/backends/cassandra.py

+ 5 - 8
celery/backends/cassandra.py

@@ -136,17 +136,16 @@ class CassandraBackend(BaseBackend):
         """Store return value and status of an executed task."""
 
         def _do_store():
-            detailed = self.detailed_mode
             cf = self._get_column_family()
             date_done = self.app.now()
             meta = {'status': status,
                     'date_done': date_done.strftime('%Y-%m-%dT%H:%M:%SZ'),
                     'traceback': self.encode(traceback),
-                    'result': result if detailed else self.encode(result),
+                    'result': self.encode(result),
                     'children': self.encode(
                         self.current_task_children(request),
                     )}
-            if detailed:
+            if self.detailed_mode:
                 cf.insert(
                     task_id, {date_done: self.encode(meta)}, ttl=self.expires,
                 )
@@ -163,11 +162,10 @@ class CassandraBackend(BaseBackend):
             try:
                 if self.detailed_mode:
                     row = cf.get(task_id, column_reversed=True, column_count=1)
-                    meta = self.decode(list(row.values())[0])
-                    meta['task_id'] = task_id
+                    return self.decode(list(row.values())[0])
                 else:
                     obj = cf.get(task_id)
-                    meta = self.meta_from_decoded({
+                    return self.meta_from_decoded({
                         'task_id': task_id,
                         'status': obj['status'],
                         'result': self.decode(obj['result']),
@@ -176,8 +174,7 @@ class CassandraBackend(BaseBackend):
                         'children': self.decode(obj['children']),
                     })
             except (KeyError, pycassa.NotFoundException):
-                meta = {'status': states.PENDING, 'result': None}
-            return meta
+                return {'status': states.PENDING, 'result': None}
 
         return self._retry_on_error(_do_get)