Skip to content

Can't Use Jinja Templating on Filtering Chart #34264

Closed

Description

@mikysetiawan

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

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • 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.

Activity

  1. dosubot commented on Jul 22, 2025

    @dosubot

    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.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about superset Share Dosu with your team

  2. mikysetiawan commented on Jul 22, 2025

    @mikysetiawan
    Author

    thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    global:jinjaRelated to Jinja templating

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions