0

I am completely baffled by this, but maybe another pair of eyes can help.

I'm passing a Model's primary_key into a Celery task that is launched via my_task.delay(args). Here's the code inside the task:

from my_project.my_app.models import *

@task()
def mytask(arg1, arg2, primary_key):
    m = Machine.objects.get(pk=primary_key)

    if m.last_os:
        last_ver = m.last_os.split('_')[1]
    else:
        last_ver = 'None'

And Celery is furious that I would even try to do this and spits out this error:

Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/celery/app/trace.py", line 238, in trace_task
R = retval = fun(*args, **kwargs)
File "/Library/Python/2.7/site-packages/celery/app/trace.py", line 416, in  __protected_call__
return self.run(*args, **kwargs)
File "/Users/me/Documents/python/my_project/my_project/my_app/tasks.py", line 33, in my_task
@task()
AttributeError: 'int' object has no attribute 'last_os'

I verify the pk that's passed to the function is indeed an int (its 1 and I'm using django's default pk assignments).

Another thing to note is that if I pass the Model instance in itself, everything works peachy keen - I just would rather not have a possibly outdated model object flying around my Celery tasks.

Any help is appreciated.

Edit: I've also tried hardcoding a pk into the Machine.objects.get(pk=1) call and it STILL thinks it's an integer, while I get a perfectly good Machine instance in the shell.

1 Answer 1

1

So it turns out that when you edit a task while the Celery service is running, those changes don't reflect on the running Celery service. So whenever you change a celery task's code, you need to restart the Celery service.

A shame the starting guides never specify this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.