[Fixed]-Using Django's ORM in a Celery Task


By default Celery pickles its task parameters. Django model instances can be pickled too.

The catch is that pickling a model instance is like taking a snapshot of it at that time. Unpickling doesn’t touch the database.

Whether this is good or bad depends, I suppose, on your needs. I tend to send a primary key into my tasks and re-query for the object in question.


You probably want to have a look at django-celery.

When doing work as a celery task, you want to pass all of the details to celery, for example to send an email, you’d pass in values for “from”, “to”, “subject”, and “body”.

If you then wanted to notify the user of the action being completed, you’d probably want to have a look at something like the messages framework in Django.

I hope that helps.


Leave a comment