docs: clarify Jinja from_dttm/to_dttm availability in SQL Lab#36544
Conversation
This commit clarifies a common source of confusion with Jinja templating:
the `from_dttm` and `to_dttm` variables are only available when a chart
or dashboard provides a time range filter context. They are NOT available
in standalone SQL Lab queries, which causes "undefined parameter" errors.
Changes:
- Updated variable descriptions to note context requirements
- Added new "Understanding Context Availability" section
- Documented three workarounds for testing in SQL Lab:
1. Using Jinja `default` filter (recommended)
2. Using SQL Lab Parameters
3. Using `{% set %}` for testing
- Added tip about filter values overriding defaults in charts
Fixes #21793
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
CodeAnt AI is reviewing your PR. |
Nitpicks 🔍
|
|
CodeAnt AI finished reviewing your PR. |
There was a problem hiding this comment.
Pull request overview
This PR clarifies when Jinja time variables (from_dttm and to_dttm) are available in Superset, addressing a long-standing source of user confusion documented in issue #21793.
- Updated variable descriptions to explicitly note they require time range filter context
- Added "Understanding Context Availability" section explaining when these variables are populated and why they fail in standalone SQL Lab queries
- Documented three practical workarounds for testing time-filtered queries in SQL Lab
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| docs/versioned_docs/version-6.0.0/configuration/sql-templating.mdx | Added context availability notes and testing workarounds for Jinja time variables |
| docs/docs/configuration/sql-templating.mdx | Same documentation updates for the current version |
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
…#36544) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
User description
SUMMARY
This PR addresses a long-standing source of confusion documented in #21793: users attempting to use
{{ from_dttm }}and{{ to_dttm }}Jinja variables directly in SQL Lab queries receive "undefined parameter" errors.Root cause: These variables are only populated when a chart or dashboard provides a time range filter context. They are NOT available in standalone SQL Lab queries.
Changes
defaultfilter (recommended){% set %}for testingBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - documentation only
TESTING INSTRUCTIONS
docs/docs/configuration/sql-templating.mdxADDITIONAL INFORMATION
superset/jinja_context.pyandsuperset/models/helpers.pyfrom_dttm/to_dttmvariables are deprecated in favor ofget_time_filter()starting in v5.0🤖 Generated with Claude Code
CodeAnt-AI Description
Docs: clarify availability of Jinja time variables and how to test in SQL Lab
What Changed
from_dttmandto_dttmare only provided when a chart or dashboard supplies a time filter and are not available in standalone SQL Lab queries (avoids "undefined parameter" errors)defaultfilter (recommended), SQL Lab Parameters, and{% set %}examples; includes a note that chart filter values override test defaultsImpact
✅ Clearer undefined-parameter errors when using Jinja in SQL Lab✅ Easier testing of time-filtered queries in SQL Lab✅ Fewer support questions about Jinja time variables💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.