Opened 6 years ago

Closed 4 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 Changed 6 years ago by Ramiro Morales

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 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Cleanup/optimization

comment:3 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 4 years ago by Claude Paroz

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