Opened 18 years ago
Closed 17 years ago
#2947 closed defect (duplicate)
ImportError raised in my management.py is swallowed
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This code in "management.py" has the same bug as was reported in ticket 2669
http://code.djangoproject.com/ticket/2669
# Import the 'management' module within each installed app, to register
# dispatcher events.
for app_name in settings.INSTALLED_APPS:
try:
import(app_name + '.management', , , [])
except ImportError:
pass
If mysite/myapp/management.py tries to import a non-existent module, or imports a module that imports a non-existent module, then management.py is ignored silently. This is very hard to diagnost and debug! At first, I had no idea why management.py seemed to cease to exist. Then after a while, I guessed, based on my knowledge of how Python works.
The solution should be the same as for 2669. Perhaps it would be good to audit all situations where ImportError is raised.
Attachments (2)
Change History (6)
comment:1 by , 18 years ago
by , 18 years ago
Attachment: | management_import_patch.diff added |
---|
Patch to fix management.py import bug
comment:2 by , 18 years ago
Note that the patch is still not quite correct. It works only if the parent of the project directory is in sys.path but I think that Django is designed to not depend upon this, right?
comment:3 by , 18 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:4 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This is really a symptom of a bigger problem with Python exceptions themselves (search python-dev for discussion of chained exceptions to see the long history here). I'm wary of working around it since it seems like a lot of code; a better aproach would be to re-raise the exception using the --traceback
mechanism added in #4431.
Maybe there should be a helper function that is used globally instead of import.