dosubot[bot] commented on issue #40119: URL: https://github.com/apache/superset/issues/40119#issuecomment-4460034359
<!-- Answer --> @ketansharma78 Based on your screenshot, the issue is likely related to **where** you're using `get_time_filter()`. This function is designed to work in a **chart/dashboard context** — not in standalone SQL Lab queries. Here's why: `get_time_filter()` reads from the chart's `form_data` which contains the time range filter applied via the UI [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/jinja_context.py#L465-L468). In a standalone SQL Lab query, there's no dashboard/chart time range context, so `from_expr` and `to_expr` will be `None` (and `time_range` will be `"No filter"`). **How to make it work:** 1. **Use it in a virtual dataset with a chart on top** — Create a dataset using your SQL query with the Jinja template, then build a chart on that dataset. When you apply a time range filter on the chart or via a dashboard filter, `get_time_filter()` will receive those values. 2. **If you need it in SQL Lab for testing**, you can use the `default` parameter to always get a value: ```sql {% set tf = get_time_filter("created_date", default="Last week") %} ``` With `default="Last week"`, it will produce valid `from_expr`/`to_expr` even without an active time filter [[2]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/jinja_context.py#L490-L502). 3. **For pure SQL Lab usage** (without chart context), consider using `from_dttm` and `to_dttm` instead, or pass the dates via `template_params` in the SQL Lab query parameters. Could you confirm whether you're running this in SQL Lab directly or as a virtual dataset with a chart? Also, what is the exact error message shown in the screenshot? <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).* --- Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset). [](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=3f9dbab5-b4ab-4c93-884d-23689da1f7bb) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
