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

runjob or runjobs will fail on an App if there happens to be a file named "jobs.py" in the root dir of that app #1836

Open
jiansongyang opened this issue Sep 9, 2023 · 0 comments

Comments

@jiansongyang
Copy link

When performing command python3 manage.py runjob -l or python3 manage.py runjobs -l on an App where a file named jobs.py is in the root direcotory of that app (example could be django-rq):

Traceback (most recent call last):
  File "manage.py", line 16, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django_extensions/management/utils.py", line 62, in inner
    ret = func(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django_extensions/management/commands/runjob.py", line 56, in handle
    print_jobs(only_scheduled=False, show_when=True, show_appname=True)
  File "/usr/local/lib/python3.6/site-packages/django_extensions/management/jobs.py", line 151, in print_jobs
    jobmap = get_jobs(when, only_scheduled=only_scheduled)
  File "/usr/local/lib/python3.6/site-packages/django_extensions/management/jobs.py", line 120, in get_jobs
    path = find_job_module(app_name, subdir)
  File "/usr/local/lib/python3.6/site-packages/django_extensions/management/jobs.py", line 83, in find_job_module
    return module.__path__[0]
AttributeError: module 'django_rq.jobs' has no attribute '__path__'

The error roots from management/jobs.py when walking through all apps to find out their jobs:

def find_job_module(app_name: str, when: Optional[str] = None) -> str:
    """Find the directory path to a job module."""
    parts = app_name.split('.')
    parts.append('jobs')
    if when:
        parts.append(when)
    module_name = ".".join(parts)
    module = importlib.import_module(module_name)
    return module.__path__[0]

Note that the attribute module.__path__ is only available in case of a package, not a .py file. We should be ready to handle this scenario.

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

1 participant