Opened 14 years ago
Closed 12 years ago
#14040 closed Cleanup/optimization (needsinfo)
Python syntax errors in module loading propagate up
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When template tags trigger the importing of modules with syntax errors, import(name) in django/utils/importlib.py raises a SyntaxError which isn't caught, and leads to confusing warnings about template syntax errors at a higher level. One solution is to trap SyntaxErrors there and wrap them as ImportErrors, which are trapped higher up.
e.g.:
django/utils/importlib.py:35
try: __import__(name) except SyntaxError, e: raise ImportError("Syntax error in " + e.filename + " at line " + str(e.lineno) + "(" + str(e.offset) + "): \"" + e.text + "\".")
Change History (5)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:5 by , 12 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
We would need a real use case to demonstrate the problem.
Note:
See TracTickets
for help on using tickets.
Thanks for the report.
That
load_module()
helper function is used in many other parts of the framework so solving this at that level wouldn't be right. Are you importing the module with syntx error at tag render time?. The case of doing that at template tag library load time is already working and there is a test case demonstrating that(tests/regressiontests/templates/templatetags/broken_tag.py).