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


When template tags trigger the importing of modules with syntax errors, import(name) in django/utils/ 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.



    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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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/

comment:2 Changed 5 years ago by julien

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:3 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 4 years ago by claudep

  • Resolution set to needsinfo
  • Status changed from new to closed

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

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