I have a celery task which updates it's state multiple times while it's running with:
current_task.update_state(state='STARTED', meta={'doing': "some message"},)
When this task returns:
return row # row is a Django model instance
The return value I get:
>> res = task_above.delay()
>> res.result
u'16'
is only the object's id as a string, not the pickled object itself.
If i remove the update_state statements, I get the correct pickled object in the task's meta (AsyncResult.result)
How can I use update_state and get the same return value (pickled object)?
I'm surprised that you can get a pickled django model instance at all, considering pickle only supports python primitives. Are you absolutely sure that you are ever getting the django model instance as a pickled result? maybe it's not going thru celery and it's not pickled?
see [this SO answer] for more about pickling django model instances1.