Bogdanp / django_dramatiq

A Django app that integrates with Dramatiq.
https://dramatiq.io
Other
331 stars 77 forks source link

TypeError: '_NamespacePath' object does not support indexing #98

Closed thebjorn closed 3 years ago

thebjorn commented 3 years ago

I've modified the code to print out the module path that fails:

go|c:\srv\www\nhosh> python manage.py rundramatiq
MODULE:PATH: None
 * Discovered tasks module: 'django_dramatiq.tasks'
MODULE:PATH: ['c:\\srv\\lib\\norsk\\norsk\\tasks']
 * Discovered tasks module: 'norsk.tasks.update_words'
MODULE:PATH: _NamespacePath(['c:\\srv\\lib\\qm\\qm\\tasks'])
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "c:\srv\venv\dev35\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "c:\srv\venv\dev35\lib\site-packages\django\core\management\__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\srv\venv\dev35\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "c:\srv\venv\dev35\lib\site-packages\django\core\management\base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "c:\users\bjorn\pycharmprojects\django_dramatiq\django_dramatiq\management\commands\rundramatiq.py", line 98, in handle
    tasks_modules = self.discover_tasks_modules()
  File "c:\users\bjorn\pycharmprojects\django_dramatiq\django_dramatiq\management\commands\rundramatiq.py", line 170, in discover_tasks_modules
    if not self._is_package(imported_module):
  File "c:\users\bjorn\pycharmprojects\django_dramatiq\django_dramatiq\management\commands\rundramatiq.py", line 188, in _is_package
    return module_path and os.path.isdir(module_path[0])
TypeError: '_NamespacePath' object does not support indexing

It's coming from an "installed" app that has a tasks directory without an __init__.py (not uncommon in our code base), so it's triggering the Implicit Namespace Packages feature.

In addition tasks.py is also the name used for invoke (http://www.pyinvoke.org/), so it would be great to have a way to override it, e.g. by settings.DJANGO_DRAMATIQ_TASK_MODULE.

I can provide a PR if it would be helpful...?

Bogdanp commented 3 years ago

A PR to add an override would be great.