Strange behavior, that I don\'t know how to explain. I\'ve got a model, Track
, with some related points
. I call a celery task to performs some calculat
You should NEVER pass model objects to celery tasks. This is because the session might expire (or be different) in the celery task compared to your Django application and this object will not be linked to the session and thus may not be available/beheave badly. What you should do is send the id. So something like track_id
and then get the object from the database by issuing a query. That should most likely solve your problem.
@shared_task
def my_task(track_id):
track = Track.query.get(track_id) # Or how ever the query should be
print 'in the task', track.id, track.points.all().count()
def some_method():
t = Track()
t.save()
t = fill_with_points(t) # creating points, attaching them to a Track
t.save()
print 'before the task', track.id, track.points.all().count()
my_task.delay(t.id) # Pass the id here, not the object