ckan / ideas

[DEPRECATED] Use the main CKAN repo Discussions instead:
https://github.com/ckan/ckan/discussions
40 stars 2 forks source link

Report reads of undefined Jinja variables #253

Open Chealer opened 4 years ago

Chealer commented 4 years ago

In CKAN 2.8.4, reading a Jinja variable which was not defined results in reading an empty string. Looping over an undefined variable will therefore quietly ignore the loop. This happens even in debug mode.

To facilitate development, such reads should be reported somehow. Jinja's StrictUndefined allows to cause a crash when reading an undefined variable, but that may be excessive even in debug mode. What I would recommend would be to define some handler which would add something to the "Debug x" section at the bottom of pages, probably in a new "Jinja warnings" subsection if there is none. Or perhaps to add a part in the paragraph of each template which generates warnings.

Jinja's make_logging_undefined() seems to allow creating such handlers. I had trouble understand its description, but the example in this message suggests it's not difficult.