-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Jinja] {{from_dttm}} and {{to_dttm}} variables not working as expected #21793
Comments
Had the same problem. |
Thanks, but it's still not working. The key is to get the SQL Lab to recognize the param, and return N/A - due to filter_value instead of Parameter error |
This is indeed an annoying bug. What I needed:
|
You can actually get around this in SQL Lab by setting the values yourself at the top of the SQL Lab window.
|
Expanding on @Ralkion's solution, I found a nice concise way to set defaults with Jinja, that doesn't overwrite actual values later: WITH
toDateTime('{{ from_dttm | default('2023-09-18T12:00:00', true) }}') AS from_dttm,
toDateTime('{{ to_dttm | default('2023-10-18T20:00:00', true) }}') AS to_dttm,
to_dttm - from_dttm AS range_dttm,
{{ row_limit | default(1000, true) }} AS row_limit
SELECT *
FROM ... NB: Alternatively, using the datetime bounds from the dataset as the defaultsWITH
(SELECT MIN( YOUR_DATETIME_FIELD ) FROM ...) AS _first_dttm,
(SELECT MAX( YOUR_DATETIME_FIELD ) FROM ...) AS _last_dttm,
toDateTime("{{ from_dttm | default('_first_dttm', true) }}") AS from_dttm,
toDateTime("{{ to_dttm | default('_last_dttm', true) }}") AS to_dttm,
to_dttm - from_dttm AS range_dttm,
{{ row_limit | default(1000, true) }} AS row_limit
SELECT *
FROM ... |
It's been a long time sine anyone touched this, and it sounds like there are valid workarounds. I'm tempted to close it as stale. Are there any proposals to be had on how to fix this more comprehensively, or docs that are worth adding to the documentation site? Is this even still an issue in 3.1/4.0 (the currently supported versions)? |
Still an issue on 4.x, I presume? It'd be appreciated if anyone can validate this in newer, better supported versions. |
Hi, I have been trying to use template sql feature without any success, i try to replicate one of the examples from docs:
Superset version: 4.1.1 |
I have met the same issue as you met.. @mnesarco |
I'm having the same problem as @mnesarco on 4.0.2. |
Description: Jinja Template {{from_dttm}} and {{to_dttm}} variables not working in SQL queries.
How to reproduce the bug
Expected results
The results filtered by the date - From A TO B
Actual results
Screenshots
Superset Jinja Variables Issue
Environment
(please complete the following information):
Checklist
Make sure to follow these steps before submitting your issue - thank you!
Additional context
#19619 The issue first discussion, but no solution so far
The text was updated successfully, but these errors were encountered: