#Problem with Django-q2 ValueError function is not defined (but it is)

9 messages · Page 1 of 1 (latest)

storm citrus
#

Im trying to create a Scheduled object and when it is running it is giving me the error ValueError function is not defined but it is, ive tried to use that path in django shell and works fine

Ive tried with async_task and works fine so dont think it is a config problem

rapid nymph
#

Can you please share the full stack trace as well as the relevant code?

storm citrus
#

this is in myapp/tasks.py

def hola_mundo(): print("Hola Mundo") return "Hola Mundo"

#

`# myapp/schedulers/scheduler.py
from django_q.models import Schedule

def schedule_hello_world():
Schedule.objects.create(
func='myapp.tasks.hola_mundo',
schedule_type=Schedule.MINUTES,
minutes=5,
repeats=-1
)
`

#

and this is the error

`
13:45:28 [Q] ERROR Failed 'myapp.tasks.hola_mundo' (echo-jig-quebec-diet) - Function myapp.tasks.hola_mundo is not defined : Traceback (most recent call last):
File "C:\route\project\venv\Lib\site-packages\django_q\worker.py", line 96, in worker
raise ValueError(f"Function {task['func']} is not defined")
ValueError: Function myapp.tasks.hola_mundo is not defined

`

#

im calling that scheduled in app.py in this way:

`
from django.apps import AppConfig

class MyAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp'

def ready(self):
    from .schedulers.scheduler import schedule_hello_world
    schedule_hello_world()

`

rapid nymph
#

Your app config shows the app name as myapp whereas the error shows conector_biloop_bitrix as being the app name.

storm citrus
#

sorry it was me renaming the functions to share it

storm citrus
#

just in case Im still having the issue 🙂