Skip to content

traceback rewriting fails to rewrite CodeType on Python>=3.10 #1535

@davidism

Description

@davidism

When rewriting a traceback, Jinja attempts to rewrite the CodeType object to change the name from the internal render function to something like "template" or "block {name}". It turns out this has been failing since 3.10 renamed a positional argument to CodeType and #1334 didn't make the correct change to address this. However, the code was surrounded by try/except Exception so it was silencing the error and all tests continued to pass.

We can use CodeType.replace to greatly simplify the code on Python 3.8+, and then only need to support one set of arguments for Python 3.7. Additionally, it seems like replacing filename again isn't needed, only the function name needs to change since the code was compiled with the correct filename already.

The try/except block is there because certain platforms such as Google App Engine apparently didn't support creating new CodeType objects at the time. It's been 13 years since then, and Google App Engine has changed significantly. I don't think its runtime is limited in that way any longer.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions