Koed00 / django-q

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

Conflicting Task model when sync = True #193

Open vindarel opened 7 years ago

vindarel commented 7 years ago

Hi ! So I'm trying to get my head around this package. I wrote an async call, following your doc (which is great !). Nothing happens, so I add sync=True and bam, I get this stacktrace:

def myhook(task):
    print task.result
    import ipdb; ipdb.set_trace()

def inventory_apply(request, pk, **kwargs):
    """Apply this inv to the stock.
    """
    from django_q.tasks import async, result
    async('models.Inventory.apply_inventory', pk, hook='myhook', sync=True)

stacktrace:

Traceback (most recent call last):
  File "/home/vince/.virtualenvs/abelujo/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/vince/projets/ruche-web/abelujo/search/models/api.py", line 959, in inventory_apply
    async('models.Inventory.apply_inventory', pk, hook='myhook', sync=True)
  File "/home/vince/.virtualenvs/abelujo/local/lib/python2.7/site-packages/django_q/tasks.py", line 49, in async
    return _sync(pack)
  File "/home/vince/.virtualenvs/abelujo/local/lib/python2.7/site-packages/django_q/tasks.py", line 675, in _sync
    cluster.worker(task_queue, result_queue, Value('f', -1))
  File "/home/vince/.virtualenvs/abelujo/local/lib/python2.7/site-packages/django_q/cluster.py", line 366, in worker
    m = importlib.import_module(module)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/vince/.virtualenvs/abelujo/local/lib/python2.7/site-packages/django_q/models.py", line 12, in <module>
    class Task(models.Model):
  File "/home/vince/.virtualenvs/abelujo/local/lib/python2.7/site-packages/django/db/models/base.py", line 309, in __new__
    new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
  File "/home/vince/.virtualenvs/abelujo/local/lib/python2.7/site-packages/django/apps/registry.py", line 221, in register_model
    (model_name, app_label, app_models[model_name], model))
RuntimeError: Conflicting 'task' models in application 'django_q': <class 'django_q.models.Task'> and <class 'models.Task'>.

My app runs well with django-q installed, only sync=True will fire this.

Can I give you more info ? On my side, I checked that I don't have a model called Task. I saw an import * in my models' __init__.py, which I tried to remove with no different result.

Django 1.8, Python2.7, django-q latest from pypi, 0.7.18

Any idea ? Thanks !

ps: is there special debugging methods ? Looks like I won't fall into my ipdb.set_prompt.

Eagllus commented 7 years ago

@vindarel a few questions. What's the backend your using? Did you start all services?

What I can see from the error message it looks like you have a models.Task class

vindarel commented 7 years ago

I'm using django's orm as cluster and cache. (and… services ?)

Maybe I have a django extension with a Task class ? (django-extensions). Will look into these then. edit: didn't find.

vindarel commented 7 years ago

According to this SO thread, the pb may arise with two different kind of imports: from django_q.models import Task (like in signals.py) along with from .models import Task (init.py).

vindarel commented 7 years ago

btw there is an interesting discussion in this old django bug report: https://code.djangoproject.com/ticket/22280#ticket and maybe particularly comment 13.