ckan / ckan/ideas

Report reads of undefined Jinja variables

Open
#253 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
39
Forks
1
PR merge metrics
No merged PRs in 30d

Description

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()](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.make_logging_undefined) seems to allow creating such handlers. I had trouble understand its description, but the example in [this message](https://stackoverflow.com/a/47466153) suggests it's not difficult.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading CKAN's Jinja environment configuration and the existing "Debug x" section described in the issue, then review Jinja's make_logging_undefined() documentation and example. Define how undefined-variable reads should be collected and displayed without causing template rendering to fail; done means warnings are visible during development while normal rendering remains usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.