Bug description

After I update my apache superset to the newest version, I can't using Jinja Template on chart filter, it showing error

Data error Invalid SQL clause: {% if true %} true {% endif %}

but when I try it in SQL Lab, it's working

before I update all my query is working well

Screenshots/recordings

Screenshot when I try to use Jinja Template in chart filter Image

Screenshot when I try in SQL Lab

Image

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Comment From: dosubot[bot]

Hi @mikysetiawan! I'm Dosu and I’m helping the superset team.

Jinja templating is no longer supported in chart filter values in recent Superset versions. This is an intentional change for security and maintainability—filter values in charts are now treated as plain SQL values and are not processed through the Jinja engine, so using template syntax like {% if ... %} in a filter will cause a SQL error instead of being evaluated as a template. In contrast, SQL Lab still processes the entire query as a Jinja template, which is why it works there.

If you need dynamic filtering with Jinja, you should include your template logic in the main SQL query or in virtual datasets, not in the filter value itself. For example, you can use Jinja in the SQL of a virtual dataset or in custom SQL expressions, and then use standard filter values in the chart controls. If you want to extend the Jinja context for supported places, you can use the ENABLE_TEMPLATE_PROCESSING feature flag and JINJA_CONTEXT_ADDONS in your superset_config.py, but this will not enable templating in chart filter values themselves. More details are in the docs.

If you need to implement conditional logic for filters, consider wrapping your logic in the main SQL using CASE WHEN or if/else blocks, as described in this issue. This approach ensures your queries remain compatible with the current Superset behavior.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

Comment From: mikysetiawan

thanks!