Opened 15 years ago
Closed 13 years ago
#11518 closed Bug (fixed)
Custom commands cannot be run from cron (or other directory) if project is not on Python Path
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | 1.1-beta |
Severity: | Normal | Keywords: | custom commands |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I wanted to create a custom command say in myproj.weather application a custom command to get_latest_weather and wanted to run that in a cron job it would fail if myproj is not on the PYTHON PATH.
I am using Python 2.6 and the imp.find_module is not finding the project path.
I can see the project module does indeed exist in sys.modules
Attachments (1)
Change History (11)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:3 by , 15 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
HI,
Maybe I was not being specific enough...
If you create a custom command in an app in your project myproj/myapp1/management/commands/my_custom_command.py and then try to use the call_command from the django.core.management
i.e.
from django.core.management import call_command
call_command('my_custom_command')
and your project is not on the PYTHONPATH, you will get a failure, because imp.find_module is not finding the myproj module that is loaded in memory.
If you add the fragment I have already mentioned it will search the sys.modules dictionary, where it does find the project's loaded module.
Please let me know if you need more details.
Regards
Mark
comment:5 by , 15 years ago
Has patch: | set |
---|
I agree not a blocker, Sorry I didn't understand the milestone setting properly!
Its a weird edge case bug, easily fixed though
comment:6 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:7 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:8 by , 13 years ago
Easy pickings: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
UI/UX: | unset |
Looks good, although getting rid of the terrible hack on PYTHON_PATH
would be even better.
comment:10 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
AFAICS, the bug can happen only when you are using the old sys.path hack that we used to use, in which a module in your project could be importable as 'myproj.myapp.mymodule' and 'myapp.mymodule'. I'm marking FIXED on that basis, since we've removed/deprecated the sys.path hack - https://docs.djangoproject.com/en/1.4/releases/1.4/#django-core-management-setup-environ
When I insert the code below at line 56 (in the ImportError exception handling) in init.py at django/core/management/ it resolves the issue
Hope that helps.