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

time_grain always return None in jinja #22774

Closed
3 tasks done
jordiisidro opened this issue Jan 18, 2023 · 27 comments
Closed
3 tasks done

time_grain always return None in jinja #22774

jordiisidro opened this issue Jan 18, 2023 · 27 comments
Assignees
Labels
#bug Bug report

Comments

@jordiisidro
Copy link

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.
@jordiisidro jordiisidro added the #bug Bug report label Jan 18, 2023
@jordiisidro
Copy link
Author

I think is related with GENERIC_CHART_AXES flag.
With charts with GENERIC_CHART_AXES=False it works well, but when I deploy with GENERIC_CHART_AXES=True only works with the chart type Table, with line or bar char doesn't work. In both cases I select for the x axe a date column.

Table chart assigns the time_grain correctly
imatge

Line chart, doesn't assign the time_grain
imatge

@jordiisidro
Copy link
Author

Solved in last version

@jordiisidro
Copy link
Author

closed incorrectly.
With the latest version the same problem still happens

@jordiisidro jordiisidro reopened this Mar 24, 2023
@villebro
Copy link
Member

@jordiisidro thanks for raising, I'll take a look next week (feel free to nag me if I don't open a PR before next weekend)

@MaksymilianME
Copy link

@villebro did you open a PR for this issue? I have the same problem with latest version for time_grains in Jinja. Thanks

@itziarmj
Copy link
Contributor

The same happens to me in version 2.1.0 with from_dttm in the edit chart. It does not happen in the charts contained in the dashboard.

@MaksymilianME
Copy link

In my opinion from_dttm works fine both for chart edition and on dasboards. But time grain parameter does not work on any chart. Only on simple Table it looks fine.

@itziarmj
Copy link
Contributor

I think is somehow related, I have managed to get time_grain None together with from_dttm None and to_dttm None.

@mtrentz
Copy link

mtrentz commented May 16, 2023

I am currently having the same problem. For me it seems to be related to the type of charts. For example, for Pivot Tables the {{ time_grain }} will always return None. But for Pivot Table (legacy) it will work.

@villebro
Copy link
Member

@itziarmj @mtrentz I think I was able to reproduce this issue - out of curiosity, have you enabled the GENERIC_CHART_AXES feature flag?

@itziarmj
Copy link
Contributor

itziarmj commented May 16, 2023 via email

@mtrentz
Copy link

mtrentz commented May 16, 2023

@villebro no, i have the following feature flags enabled.

FEATURE_FLAGS = {
        "ALERT_REPORTS": True,
        "ENABLE_TEMPLATE_PROCESSING": True,
        "DASHBOARD_RBAC": True,
        "DRILL_BY": True,
        "DRILL_TO_DETAIL": True,
    }

@villebro
Copy link
Member

Ok thank's for confirming @mtrentz @itziarmj - I think I know what's going on, I can probably get this fixed this week to get it into 2.1.1

@MaksymilianME
Copy link

Hi @villebro did you manage to fix this issue? This holds me back from moving from 2.0 to 2.1. Cant wait to start using 2.1.
Thanks!

@mapledan
Copy link
Contributor

mapledan commented Jul 3, 2023

@villebro no, i have the following feature flags enabled.

FEATURE_FLAGS = {
        "ALERT_REPORTS": True,
        "ENABLE_TEMPLATE_PROCESSING": True,
        "DASHBOARD_RBAC": True,
        "DRILL_BY": True,
        "DRILL_TO_DETAIL": True,
    }

This PR(#23652 ) change the default value of GENERIC_CHART_AXES to true.
You should set GENERIC_CHART_AXES to false.

@unnyns-307
Copy link

Hello, also facing the same problem.
We cannot disable GENERIC_AXIS_CHART on Superset cause there are many charts created based one the chart types enabled from this feature flag.
Do we have other alternatives for this case or specific fixing on the code could resolve this too?

@howardcho
Copy link

@villebro did the fix for from_dttm make it into version 2.1? I'm using 2.0, and am seeing this issue as well.

I have the following feature flags:

FEATURE_FLAGS = {
        "ALERT_REPORTS": True,
        "ENABLE_TEMPLATE_PROCESSING": True,
        "GENERIC_CHART_AXES": True
}

@duvenagep
Copy link

@villebro Any status on this issue. Currently using Superset 3.0.0rc2 and now GENERIC_CHART_AXES=true is the default this issues still seems to persist. Can confirm it works normally on tables but not on line graphs

@rumbin
Copy link
Contributor

rumbin commented Oct 26, 2023

The issue still exists in 3.0.1, as it seems. @villebro, you seemed confident to know what needs to be fixed. Any update on this?

@mapledan
Copy link
Contributor

I create the PR #25429 that fix for the from_dttm return None, but I'm not sure about the time_grain issue.

@WojtekWaga
Copy link

Hey, it looks like it does not help for time_grain

@rzzldzzl
Copy link

rzzldzzl commented Nov 3, 2023

Running the latest dev version of superset -
Regardless of "GENERIC_CHART_AXES" being set to True||False, time_grain returns None on the line & bar charts. time_grain does return correctly on the table chart, however.

@Vitor-Avila
Copy link
Contributor

I believe this got fixed with #25842 cc @rusackas

@stepcheunghk
Copy link

I believe this got fixed with #25842 cc @rusackas

Thanks for the update @Vitor-Avila, however it seems it only works for v3.0?

@Vitor-Avila
Copy link
Contributor

@stepcheunghk unsure about the version the PR got associated with. @rusackas would you be able to assist determining that? I believe we're also good to close this bug.

@mtrentz
Copy link

mtrentz commented Jan 15, 2024

@Vitor-Avila Hey, coincidentally I've just tested this out. Using docker the 3.0.2 version fixed this issue for me while the 3.0.0 hadn't done so beforehand.

@rusackas
Copy link
Member

Thanks for the update @mtrentz - sounds like we ca close this one then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#bug Bug report
Projects
None yet
Development

No branches or pull requests