Search code examples
djangodjango-templatescelerydjcelery

celery tasks converts python list into strings. how to avoid this?


I have an email sending tasks running in celery shared task. i am passing a python list into html template. but celery converts this list into string. but without using celery task , i am getting actual list.


Solution

  • From the docs you can read:

    Data transferred between clients and workers needs to be serialized, so every message in Celery has a content_type header that describes the serialization method used to encode it.

    The default serializer is JSON, but you can change this using the task_serializer setting, or for each individual task, or even per message.

    As serializers, you can use also pickle, yaml and msgpack but the data, MUST be serialized.

    Conclusion:

    Serialization is mandatory, just keep in mind tasks will be communicating using JSON (that's your case) and de-serialize the data before using it.