Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError('need more than 1 value to unpack',) #171

Closed
rwoloszyn opened this issue May 22, 2016 · 7 comments
Closed

ValueError('need more than 1 value to unpack',) #171

rwoloszyn opened this issue May 22, 2016 · 7 comments

Comments

@rwoloszyn
Copy link

rwoloszyn commented May 22, 2016

I am testing django-q as production msg que and schedule library. I made simple function:

@login_required
def makea_math(request):
    resp = {}
    resp['retrr'] = result(async('math_task', '123131.12312'), 100)
return HttpResponse(json.dumps(resp), content_type="application/json")
...
def math_task(number):
    return math.ceil(number)

but each time I get the error from broker:
ValueError('need more than 1 value to unpack'

Is there any way to debug or check broker logs and check what went wrong ?

I am running Django : 1.9.6
Django REST framework: 3.3.2

@thinkwelltwd
Copy link

I would check the resulting Task object that was created; I've gotten that error when the task had no args / kwargs.

@qb1989
Copy link

qb1989 commented May 25, 2016

I just implemented your code snippet and debugged it.
The error comes not from the Broker but from the Cluster itself in line:360
Seems like there are some probs on how the functions (eg. math_task) are imported cause there is no problem with your code when you create a task.py which contains all your django_q tasks.

So maybe try to create a task.py file containing all your tasks and execute them like this:
async('examplepath.tasks.math_task', 123131.12312)

@Koed00
Copy link
Owner

Koed00 commented May 25, 2016

yes @qb1989 is right.

You either reference the function directly without quotes:

@login_required
def makea_math(request):
    resp = {}
    resp['retrr'] = result(async(math_task, '123131.12312'), 100)
return HttpResponse(json.dumps(resp), content_type="application/json")

This works fine with local functions and classes.

Or you have to use the full paths to the functions:

@login_required
def makea_math(request):
    resp = {}
    resp['retrr'] = result(async('my_project.views.math_task', '123131.12312'), 100)
return HttpResponse(json.dumps(resp), content_type="application/json")

This is what I tend to do all the time.

The reason you see that error, is cause you are feeding the result function the import error as its first parameter.

@rwoloszyn
Copy link
Author

@ Koed00 thanks. That was exactly the issue. I managed to fix this before your answer but thanks
for help anyway.

@Koed00
Copy link
Owner

Koed00 commented May 28, 2016

Awesome. Sorry, sometimes I don't respond as fast as I'd like to.
Enjoy 👍

@Koed00 Koed00 closed this as completed May 28, 2016
@sato-s
Copy link

sato-s commented Jan 23, 2018

This library is very useful and I really appreciate for it.
But, this behavior is completely cryptic.

In my case.

async('async_tasks.finish_practice', 3, sync=True)

results in No module named 'async_tasks'

async(async_tasks.finish_practice, 3, sync=True)

works without problem.

Could you reopen and shed light on this issue?

  • Python 3.6.2
  • django-q 0.9.0
  • django 2.0

@Koed00
Copy link
Owner

Koed00 commented Jan 23, 2018

If you are going to use the quoted path you will have to include the base module:

async('my_main_module.tasks.async_tasks.finish_practice', 3, sync=True)

That string needs to be importable from the root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants