Skip to content
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

{{ from_dttm }} and {{ to_dttm }} Jinja special variables are not rendered in Custom SQL metrics #19564

Closed
3 tasks done
EBoisseauSierra opened this issue Apr 6, 2022 · 0 comments · Fixed by #19565
Closed
3 tasks done
Labels
#bug Bug report v1.5

Comments

@EBoisseauSierra
Copy link
Contributor

When using Jinja special variables in Custom SQL metrics (Explore Panel), {{ from_dttm }} and {{ to_dttm }} are not rendered — unlike, say, {{ current_user_id() }}.

How to reproduce the bug

Turn Jinja templating feature flag on:

FEATURE_FLAGS ={
    "ENABLE_TEMPLATE_PROCESSING": True,
}
  1. Go to your_dataset/BigNumber/Explore Panel
  2. Click on Metric/Custom SQL
  3. Use following definition:
    a. MIN({{ current_user_id() }})
    b. MIN('{{ from_dttm }}')

Expected results

Both definitions to return a number.

Actual results

  • MIN({{ current_user_id() }}) returns a result:

Screenshot from 2022-04-06 14-31-25_shadow

by executing the following query

SELECT MIN(3) AS "MIN({{ current_user_id() }})"
FROM my.db
WHERE timestamp >= TO_TIMESTAMP('2022-03-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
  AND timestamp < TO_TIMESTAMP('2022-04-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US');
  • But MIN('{{ from_dttm }}') returns “No Data” (even with a Time Range filter set).

Screenshot from 2022-04-06 14-31-04_shadow

executing this query:

SELECT MIN('{{ from_dttm }}') AS "MIN('{{ from_dttm }}')"
FROM my.db
WHERE timestamp >= TO_TIMESTAMP('2022-03-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
  AND timestamp < TO_TIMESTAMP('2022-04-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US');

Environment

(please complete the following information):

Checklist

Make sure to follow these steps before submitting your issue - thank you!

  • I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • I have reproduced the issue with at least the latest released version of superset.
  • I have checked the issue tracker for the same issue and I haven't found one similar.

Additional context

  • Database engine: PostgreSQL
  • The only valid syntax for {{ from_dttm }} is using single quotes (i.e. sum('{{ from_dttm }}')). Indeed, both {{ from_dttm }} (no quotes) or "{{ from_dttm }}" (double quotes) yield an error.
@EBoisseauSierra EBoisseauSierra added the #bug Bug report label Apr 6, 2022
@EBoisseauSierra EBoisseauSierra changed the title {{ from_dttm }} and {{ to_dttm }} Jinja special variables are not rendered in Custom SQL metrics {{ from_dttm }} and {{ to_dttm }} Jinja special variables are not rendered in Custom SQL metrics Apr 6, 2022
@villebro villebro added the v1.5 label Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#bug Bug report v1.5
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants