Lipau3n
Lipau3n

Reputation: 75

FileNotFoundError inside a celery task

I have a celery task that operate with file from Django model

class Something(models.Model):
    doc = models.FileField()

@app.task
def operate_with_file(instance_id: int):
    instance = Something.objects.get(id=instance_id)
    size = instance.doc.file.size

When celery worker run this task i got error FileNotFoundError on string size = instance.doc.file.size. If i call operate_with_file manually from django shell that works fine. File already exists in a model. What wrongs with this?

Upvotes: 1

Views: 447

Answers (1)

2ps
2ps

Reputation: 15926

This probably has to do with which server the code is being run from. The server on which the celery task is running may be different than the server on which you are running django shell.

Upvotes: 3

Related Questions