Skip to content

time_grain always return None in jinja #22774

@jordiisidro

Description

@jordiisidro

A clear and concise description of what the bug is.

How to reproduce the bug

The variable time_grain used in SQL templating is always None
Other variables like from_dttm work fine.

Sample query:

select date_trunc(
{%- if time_grain == 'P1D' -%}
'day'
{%- elif time_grain == 'P1W' -%}
'week'
{%- elif time_grain == 'P1M' -%}
'month'
{%- elif time_grain == 'P3M' -%}
'quarter'
{%- elif time_grain == 'P1Y' -%}
'year'
{%- elif time_grain == 'P1Y' -%}
'year'
{% else %}
'month'
{%- endif -%}
, data) as data
, tecnologia, proveidor, count(distinct id_ticket) as incidencies
from inc_pet i
where {% if from_dttm is not none %}
i.data >= '{{ from_dttm }}' AND
{% endif %}
{% if to_dttm is not none %}
i.data < '{{ to_dttm }}' AND
{% endif %}
1=1
group by date_trunc(
{%- if time_grain == 'P1D' -%}
'day'
{%- elif time_grain == 'P1W' -%}
'week'
{%- elif time_grain == 'P1M' -%}
'month'
{%- elif time_grain == 'P3M' -%}
'quarter'
{%- elif time_grain == 'P1Y' -%}
'year'
{%- elif time_grain == 'P1Y' -%}
'year'
{% else %}
'month'
{%- endif -%}
, data)
, tecnologia, proveidor

Expected results

I expect that when Granularity chances the time_grain value changes

Actual results

time_grain always return None

Environment

  • superset version: 2.0.1

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.

Metadata

Metadata

Assignees

Labels

#bugBug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions