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

Not enough values to unpack (expected 2, got 1) #314

Closed
nastyaDjo opened this issue Aug 22, 2018 · 7 comments
Closed

Not enough values to unpack (expected 2, got 1) #314

nastyaDjo opened this issue Aug 22, 2018 · 7 comments

Comments

@nastyaDjo
Copy link

Hello!
I faced with this problem when I try to run command python manage.py qcluster:

[Q] INFO Q Cluster-21177 starting.
[Q] INFO Process-1:1 ready for work at 21181
[Q] INFO Process-1:2 ready for work at 21182
[Q] INFO Process-1:3 ready for work at 21183
[Q] INFO Process-1:4 ready for work at 21184
[Q] INFO Process-1:5 monitoring at 21185
[Q] INFO Process-1 guarding cluster at 21180
[Q] INFO Process-1:6 pushing tasks at 21186
[Q] INFO Q Cluster-21177 running.
[Q] INFO Enqueued 2
[Q] INFO Process-1 created a task from schedule [check_achievements_monthly]
[Q] INFO Process-1:1 processing [two-nineteen-may-pasta]
[Q] ERROR Failed [two-nineteen-may-pasta] - not enough values to unpack (expected 2, got 1)

I use Python 3.7, Django 2.0.7

from datetime import datetime
from django.contrib.auth.models import User
from django_q.tasks import schedule
from pytz import timezone

from achievements.models import Achievement, UserAchievement


def check_ach(*args, **kwargs):
    for achievement in Achievement.objects.filter(period=args[0]):
        for user in User.objects.all():
            try:
                user_achievement = achievement.users_achievements.get(user=user)
            except UserAchievement.DoesNotExist:
                user_achievement = None

            if user_achievement and user_achievement.max_amount_reached:
                continue  # user already has maximal amount of that achievement - skip

            if achievement.is_earned(user):
                UserAchievement.objects.create(achievement=achievement, user=user)


schedule(check_ach,'MONTHLY', name='check_achievements_monthly', schedule_type='M', next_run=datetime.now().astimezone(timezone('Europe/Kiev')))

Can you help me with this issue?

@bronte2k7
Copy link

Have you solved the problem?

@mm-matthias
Copy link

I see this issue when requeing a failed task via the admin panel.

@GodMode-On
Copy link

GodMode-On commented Mar 22, 2019

I figured, that when getting Task from db(IDK for cache), attr func became str. For example:

ipdb> Task.objects.get(id='3feb3f42b87740519bf2ca37245fbb51') == task  # just created Task
True
ipdb> Task.objects.get(id='3feb3f42b87740519bf2ca37245fbb51').func
'<function send_email_message at 0x7f15d126a268>'
ipdb> task.func
<function send_email_message at 0x7f15d126a268>
ipdb> Task.objects.get(id='3feb3f42b87740519bf2ca37245fbb51').func == task.func
False
ipdb> hash(Task.objects.get(id='3feb3f42b87740519bf2ca37245fbb51'))
-3466111266535390795
ipdb> hash(task)
-3466111266535390795

@GodMode-On
Copy link

GodMode-On commented Mar 22, 2019

@mm-matthias @bronte2k7 @nastyaDjo I fixed it: in task pass not function instance, but path to it as str.
For example: 'users.emails.send_email_message' instead of send_email_message

@neilfrndes
Copy link

neilfrndes commented Jun 1, 2019

Digging into the source to see why 'users.emails.send_email_message' works and not 'send_email_message'. This is how the django q executes the task when a string is entered

fn = 'dotted.function.string'
module, func = fn.rsplit('.', 1)
m = importlib.import_module(module)
f = getattr(m, func)
f(*args, **kwargs) 

@mrname
Copy link

mrname commented Aug 21, 2019

Can confirm that like @mm-matthias I get this issue when resubmitting tasks in the admin panel.

EDIT: If the task is initially submitted as a FULL string (with module path), as described by GodMode-On, admin functionality works. So to be clear, the bug here is that when using async_task with a method (as opposed to a string), attempting to re-submit a task fails.

@vladkhard
Copy link

@mm-matthias @bronte2k7 @nastyaDjo I fixed it: in task pass not function instance, but path to it as str.
For example: 'users.emails.send_email_message' instead of send_email_message

@GodMode-On thanks a lot, your solution works just fine :)

kennyhei added a commit to kennyhei/django-q that referenced this issue May 8, 2021
kennyhei added a commit to kennyhei/django-q that referenced this issue May 9, 2021
…se so that resubmitting failed task works
kennyhei added a commit to kennyhei/django-q that referenced this issue May 10, 2021
…se so that resubmitting failed task works
@Koed00 Koed00 closed this as completed in 1eb5cf4 May 14, 2021
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

7 participants