Koed00 / django-q

A multiprocessing distributed task queue for Django
https://django-q.readthedocs.org
MIT License
1.83k stars 290 forks source link

ERROR malformed node or string: <_ast.Name object at 0x7fba399cc080> #456

Open pedrovgp opened 4 years ago

pedrovgp commented 4 years ago

I have created a Schedule through the shell, like this:

Schedule.objects.get_or_create(
    name='send_csat_survey_emails_temp',
    defaults=dict(
        func='django.core.management.call_command',
        args="send_csat_survey_emails",
        schedule_type=Schedule.MINUTES,
        repeats=-1,  # repeats forever
        next_run=datetime.now(),
    )
)

It was successfully created.

But no task is queued and qcluster logs: [Q] ERROR malformed node or string: <_ast.Name object at 0x7fba399cc278>

I have tried changing the name of the Schedule, but I got the same error.

Am I doing something wrong?

Koed00 commented 4 years ago

Usually this means that somewhere there is a string evaluated that is not correct python. Are you calling a valid management command? And are you sure the error is not happening there?

pedrovgp commented 4 years ago

I found the problem. args should be a tuple. It must be unpacked somewhere in the code. Changing to

Schedule.objects.get_or_create(
    name='send_csat_survey_emails_temp',
    defaults=dict(
        func='django.core.management.call_command',
        args=("send_csat_survey_emails",),
        ...
    )
)

did it.

The docs here show the Schedule class being instatiated with args="2,-2". I guess that was the origin of my confusion. For sanity sake, I tried args="send_csat_survey_emails, ", but that did not work either.

I don't know if you want to keep the issue open (you may want to update docs or so), but feel free to close it. I am using Python 3.8 and Django 2.2 by the way.

Koed00 commented 4 years ago

I think it has more to do with how call_command handles parameters .That particular example in the docs works well. I'll dig into it a bit to see what I can find.

jonaswinkler commented 3 years ago

Can confirm that this happens when anything that's not a tuple is specified in args. The function name does not matter; in fact, it doesn't even has to be a valid function.

Similar error for kwargs - if anything but a dictionary is specified, an error is raised:

13:33:38 [Q] ERROR name 'asdf' is not defined

This is very easy to mess up since you can define schedules in the admin, and the help text does not even specify the correct format for these fields.

horizon365 commented 5 months ago

we call check the field 'args' in table django_q_schedule , it must be like ('sync_file',)