Opened 14 years ago

Closed 11 years ago

#14040 closed Cleanup/optimization (needsinfo)

Python syntax errors in module loading propagate up

Reported by: jt@… 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 Ramiro Morales, 13 years ago

Triage Stage: UnreviewedAccepted

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).

comment:2 by Julien Phalip, 13 years ago

Severity: Normal
Type: Cleanup/optimization

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Claude Paroz, 11 years ago

Resolution: needsinfo
Status: newclosed

We would need a real use case to demonstrate the problem.

Note: See TracTickets for help on using tickets.
Back to Top