8

Do similar as here Retrieving GroupResult from taskset_id in Celery?. But after

tasks.save()

I get this error:

Traceback (most recent call last):


File "/home/rodions/pma/pma/pma/controllers/report/cross_site_stock.py", line 270, in report_cross_site_stock_refresh
    tasks.save()
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/result.py", line 769, in save
    return (backend or self.app.backend).save_group(self.id, self)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/backends/base.py", line 325, in save_group
    return self._save_group(group_id, result)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/backends/mongodb.py", line 170, in _save_group
    'result': Binary(self.encode(result)),
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/backends/base.py", line 182, in encode
    _, _, payload = dumps(data, serializer=self.serializer)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/kombu-3.0.24-py2.7.egg/kombu/serialization.py", line 164, in dumps
    payload = encoder(data)
  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/kombu-3.0.24-py2.7.egg/kombu/serialization.py", line 59, in _reraise_errors
    reraise(wrapper, wrapper(exc), sys.exc_info()[2])
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/kombu-3.0.24-py2.7.egg/kombu/serialization.py", line 55, in _reraise_errors
    yield
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/kombu-3.0.24-py2.7.egg/kombu/serialization.py", line 164, in dumps
    payload = encoder(data)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/anyjson-0.3.3-py2.7.egg/anyjson/__init__.py", line 141, in dumps
    return implementation.dumps(value)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/anyjson-0.3.3-py2.7.egg/anyjson/__init__.py", line 87, in dumps
    return self._encode(data)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/simplejson-3.6.5-py2.7-linux-x86_64.egg/simplejson/__init__.py", line 370, in dumps
    return _default_encoder.encode(obj)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/simplejson-3.6.5-py2.7-linux-x86_64.egg/simplejson/encoder.py", line 269, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/simplejson-3.6.5-py2.7-linux-x86_64.egg/simplejson/encoder.py", line 348, in iterencode
    return _iterencode(o, 0)
  File "/home/rodions/pma/env/local/lib/python2.7/site-packages/simplejson-3.6.5-py2.7-linux-x86_64.egg/simplejson/encoder.py", line 246, in default
    raise TypeError(repr(o) + " is not JSON serializable")
EncodeError: <GroupResult: 3up2n4tWLihRe2Mx7P7B8Z [b58ae08c-6837-47c1-bf0c-4fb68d032ab4, a9775214-1e7f-4b8d-a57e-b73d76fbff21, bdd2826f-b811-4c68-8e8f-f23d5cada36f]> is not JSON serializable

This is my code:

group_tasks = group([save_to_cross_site_stock_report.s(batch, unique_id) for batch in grouper(100, rows, None)])
tasks = group_tasks.apply_async(task_id=unique_id)
tasks.save()

ini file:

[celery]
CELERY_RESULT_BACKEND = mongodb://localhost:27017/jobs_result
BROKER_URL = mongodb://localhost:27017/jobs
CELERY_ACCEPT_CONTENT = json
CELERY_RESULT_SERIALIZER = json
CELERY_TASK_SERIALIZER = json

I`m workin in pyramid and using the pyramid_celery. I need to refer to a group of tasks by id in another controller to check how many tasks completed.

Why I get this error? And how does it fix?

Community
  • 1
  • 1
isrodick
  • 261
  • 3
  • 9
  • 1
    Got the same issue, seems as though the message payload serialization is done with [json](https://docs.python.org/2/library/json.html). In other words, whatever args you're passing to your queue must be immutable (they don't really make this clear in the Celery docs). Read more about the module Celery is using for serialization here: http://docs.celeryproject.org/projects/kombu/en/latest/userguide/serialization.html – rob Jan 16 '17 at 18:27

0 Answers0