Model object losing set attributes when passed to callback function

8 views
Skip to first unread message

Salvatore Iovene

unread,
Dec 2, 2011, 12:41:21 AM12/2/11
to celery...@googlegroups.com
Hi,
in one of my tasks I set some property on a model object: Image. Here's some relevant extract of the code:

@task()
def store_image(image, callback = None):
  (w, h) = save_image_to_amazon_s3(image)
  image.w = w
  image.h = h
  print image.w, image.h

  if callback is not None:
    subtask(callback).delay(image)


And here is the callback:

@task()
def image_stored_cb(image):
  print image.w, image.h

And this is how I call the first task:

store_image.delay(image, callback = image_stored_cb)


Now, as you guessed from the subject of my message, when I print image.w and image.h in the callback, they are both empty, even though they are printed correctly in the first task.
If, in the first task, I do image.save() before calling the callback, everything works fine, but the thing is that I can't save the image there, because the user might have deleted it in the meantime.

Is this the expected behavior or is there something I'm doing wrong? Do you have any recommendations?

Thanks!
Reply all
Reply to author
Forward
0 new messages