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

Not able to use get_time_filter function #31598

Open
3 tasks done
Keveen-ghori opened this issue Dec 23, 2024 · 4 comments
Open
3 tasks done

Not able to use get_time_filter function #31598

Keveen-ghori opened this issue Dec 23, 2024 · 4 comments
Labels
global:jinja Related to Jinja templating

Comments

@Keveen-ghori
Copy link

Bug description

I am creating dataset for dynamic date range filter and dataset look like below query:

{% set time_filter = get_time_filter("bucket", default="Last week", remove_filter=True) %}
WITH calculated_data AS (
    SELECT 
        (wspmcdd.bucket AT TIME ZONE 'AUSTRALIA/BRISBANE' + INTERVAL '1 day') AS "date",
        wspmcdd.meter_id,
        wspmcdd.meter_channel_id,
        wspmcdd.maximum_value,
        wspmcdd.minimum_value,
        ROUND(
            CASE
                WHEN wspmcdd.channel_type = 'Interval' THEN wspmcdd.total_value::NUMERIC
                WHEN wspmcdd.channel_type = 'Cumulative' THEN (wspmcdd.maximum_value - LAG(wspmcdd.maximum_value) OVER (
                    PARTITION BY wspmcdd.meter_id, wspmcdd.meter_channel_id
                    ORDER BY wspmcdd.bucket
                ))::NUMERIC
                ELSE wspmcdd.total_value::NUMERIC
            END, 3
        ) AS calculated_value,
        wspmcdd.status,
        wspmcdd.nem12_status,
        wspmcdd.meter_type,
        wspmcdd.channel_type,
        wspmcdd.unit_of_measurement,
        wspmcdd.meter_property_name,
        wspmcdd.customer_name,
        wspmcdd.site_name,
        wspmcdd.physical_time_zone,
        wspmcdd.channel_name,
        wspmcdd.average_value,
        wspmcdd.reading_count,
        '{{ time_filter.time_range }}' AS time_range
    FROM 
        west_Side_place_meter_channel_data_daily AS wspmcdd
    JOIN 
        Dashboard_Meter_Type_Channel_Configuration AS dmtcc 
        ON lower(dmtcc.channel_name) = lower(wspmcdd.channel_name)
        AND dmtcc.meter_type = wspmcdd.meter_type
        AND lower(dmtcc.unit_of_measurement) = lower(wspmcdd.unit_of_measurement)
        AND lower(dmtcc.channel_type) = lower(wspmcdd.channel_type)
    WHERE wspmcdd.bucket >= ((TIMESTAMP {{ time_filter.from_expr }} + INTERVAL '-1 day') AT TIME ZONE 'AUSTRALIA/BRISBANE')
      AND wspmcdd.bucket < ((TIMESTAMP {{ time_filter.to_expr }}) AT TIME ZONE 'AUSTRALIA/BRISBANE')
      AND wspmcdd.meter_type = 'Electricity'
)
SELECT *
FROM 
    calculated_data
WHERE 
    "date" > ((TIMESTAMP {{ time_filter.to_expr }}))
ORDER BY 
    "date";

But i am getting error Error: Error while rendering virtual dataset query: 'get_time_filter' is undefined.

Screenshots/recordings

No response

Superset version

4.1.1

Python version

3.11

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Copy link

dosubot bot commented Dec 23, 2024

The error message 'get_time_filter' is undefined suggests that the get_time_filter function is not available in the Jinja context for your SQL template. Here are a few steps to troubleshoot and resolve this issue:

  1. Enable Template Processing: Ensure that the ENABLE_TEMPLATE_PROCESSING feature flag is set to True in your superset_config.py file. This is necessary for using Jinja templating features like get_time_filter.

    # In superset_config.py
    FEATURE_FLAGS = {
        'ENABLE_TEMPLATE_PROCESSING': True,
    }
  2. Check Jinja Context: Verify that the get_time_filter function is included in the Jinja context. This function should be part of the default Jinja context in Superset version 4.1.1, but if it's not, you might need to add it manually or check if there are any custom configurations that might be overriding the default context.

  3. Superset Version: Ensure that you are indeed using Superset version 4.1.1, as get_time_filter is available in this version [1].

  4. Restart Superset: After making changes to the configuration, restart your Superset server to apply the changes.

If these steps do not resolve the issue, there might be a deeper configuration problem or a bug in your specific setup.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added the global:jinja Related to Jinja templating label Dec 23, 2024
@sonfire186
Copy link

# In superset_config.py
FEATURE_FLAGS = {
    'ENABLE_TEMPLATE_PROCESSING': True,
}

Not work

@Keveen-ghori
Copy link
Author

I already added that flag, but still getting same error.

@zackertypical
Copy link

same to me, in doc: https://github.com/apache/superset/blob/master/docs/docs/configuration/sql-templating.mdx
It says that

 from_dttm: start datetime value from the selected time range (None if undefined) (deprecated beginning in version 5.0, use get_time_filter instead)
to_dttm: end datetime value from the selected time range (None if undefined). (deprecated beginning in version 5.0, use get_time_filter instead)

but there is no version 5.0,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
global:jinja Related to Jinja templating
Projects
None yet
Development

No branches or pull requests

3 participants