Issues with image.path being reported wrong causing failing of a Celery task

24 views
Skip to first unread message

Paul

unread,
Jan 17, 2018, 10:17:07 AM1/17/18
to Django users

I have the following model:


class Image(models.Model): image = models.ImageField(upload_to=file_upload_to)


I have a dynamic file_upload function:


def file_upload_to(instance, filename):
 
base = '_'.join([str(instance.item.pk), instance.item.slug])
 
return os.path.join('accounts', base, 'item', base_2, 'images', filename)

and in a ModelForm:


class ImageModelForm(ModelForm)
 
def save(self, commit=True):
  image_obj
= super().save(commit=commit)
  product_image__task
.delay(image_obj.image.path, image_obj.image.name, image_obj.product_id) return image_obj



I tried also to wait for transaction:


transaction.on_commit( lambda: product_image_crop_task.delay(image_obj.image.path, image_obj.image.name, image_obj.product_id))



The file is saved properly in a path like:


media/account/12_blue/images/image_name.jpeg



The problem is that image_obj.image.path is not reporting the correct path, but this path:


media/image_name.jpeg


I use the image path, further passing it as an argument to a task, but because I received the wrong path, it will fail.


How can I fix this, and receive the correct path ?  I tried also using time.sleep(), nothing works, the path/location returned is wrong, even if is saved to the correct one.

Matemática A3K

unread,
Jan 17, 2018, 11:37:40 AM1/17/18
to django...@googlegroups.com

b
The first thing I would do is to comment out all the celery tasks to see if those are messing with path property (you are not using a custom storage, right?) Also, the upload_to function you posted does not correspond to the path generated, try to post the latest code :)
 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d57595e-95b5-49f4-a29a-34f73e30620d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul

unread,
Jan 17, 2018, 12:19:03 PM1/17/18
to Django users
I did, is not celery related.

The only thing, that maybe is influencing the path, is that the Image model is used in an inlineformset.

b
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages