Skip to content

fix(jinja): expose dialect-escaped companion value on get_filters()#40531

Draft
sha174n wants to merge 7 commits into
apache:masterfrom
sha174n:fix/template-filter-escape-helper-202605292158
Draft

fix(jinja): expose dialect-escaped companion value on get_filters()#40531
sha174n wants to merge 7 commits into
apache:masterfrom
sha174n:fix/template-filter-escape-helper-202605292158

Conversation

@sha174n
Copy link
Copy Markdown
Contributor

@sha174n sha174n commented May 29, 2026

ExtraCache.get_filters() and _get_filters_from_query_context() now expose a companion escaped_val key on each returned filter dict whenever a SQL dialect is configured. The value is produced via String().literal_processor, the same path already used by url_param, so the quoting rules track the active dialect.

val continues to carry the raw value for non-SQL uses (comparison, logging, where_in). The companion key is opt-in: only templates that read filter.get('escaped_val') see the processed form, so existing templates and downstream consumers are unaffected. The docstring example now demonstrates the LIKE interpolation pattern with escaped_val, replacing the manual replace("'", "''") snippet that worked only for a subset of dialects.

Unit tests cover the string, list-of-string, and query_context_filters paths, plus a no-dialect case asserting the key is absent so the prior return schema is preserved.

Testing

  • pytest tests/unit_tests/jinja_context_test.py -k get_filters

Checklist

  • Has associated issue: N/A (incremental hardening, ride-along with docstring update)
  • Required feature flags: N/A
  • Changes are backwards compatible
  • Relevant documentation has been updated
  • Unit tests have been added

Add an `escaped_val` key to the dict returned by `ExtraCache.get_filters()`
and `_get_filters_from_query_context()` whenever a SQL dialect is
configured. The value is produced via `String().literal_processor`,
the same path already used by `url_param`, so the escape rules track
the active dialect. `val` continues to expose the raw value for
non-SQL uses such as comparison, logging, or feeding `where_in`.

The companion key is opt-in for templates: only callers that read
`filter.get('escaped_val')` see the processed form, so existing
templates and consumers are unaffected. The docstring example now
demonstrates the `LIKE` interpolation pattern with `escaped_val`,
replacing the manual `replace("'", "''")` snippet that worked for
only a subset of dialects.

Unit tests cover the string, list-of-string, and
query_context_filters paths, plus a no-dialect case asserting the
key is absent so the previous return schema is preserved.
@github-actions
Copy link
Copy Markdown
Contributor

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

Please read our New Contributor Welcome & Expectations guide.

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 16.66667% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.96%. Comparing base (acc8024) to head (5f0d63e).

Files with missing lines Patch % Lines
superset/jinja_context.py 16.66% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40531      +/-   ##
==========================================
- Coverage   63.97%   63.96%   -0.01%     
==========================================
  Files        2654     2654              
  Lines      142753   142768      +15     
  Branches    32833    32838       +5     
==========================================
+ Hits        91325    91327       +2     
- Misses      49870    49883      +13     
  Partials     1558     1558              
Flag Coverage Δ
hive 39.72% <16.66%> (-0.01%) ⬇️
mysql 58.41% <16.66%> (-0.02%) ⬇️
postgres 58.49% <16.66%> (-0.02%) ⬇️
presto 41.33% <16.66%> (-0.01%) ⬇️
python 59.98% <16.66%> (-0.02%) ⬇️
sqlite 58.14% <16.66%> (-0.02%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant