Bug description
Sql Query:
{% set time_filter = get_time_filter("order_date", remove_filter=True) %}
{% set from_expr = time_filter.from_expr %}
{% set to_expr = time_filter.to_expr %}
{% set time_range = time_filter.time_range %}
SELECT
*,
'{{ time_range }}' as applied_time_range
FROM cleaned_sales_data
WHERE 1 = 1
{% if from_expr %}AND order_date >= {{ from_expr }}{% endif %}
{% if to_expr %}AND order_date < {{ to_expr }}{% endif %}
Template parameters:
{
"_filters": [
{
"col": "order_date",
"op": "TEMPORAL_RANGE",
"val": "2003-01-01 : 2003-12-31"
}
]
}
Error:
Parameter error
Failed to execute query '12' - '{% set time_filter = get_time_filter("order_date", remove_filter=True) %}
{% set from_expr = time_filter.from_expr %}
{% set to_expr = time_filter.to_expr %}
{% set time_range = time_filter.time_range %}
SELECT
*,
'{{ time_range }}' as applied_time_range
FROM cleaned_sales_data
WHERE 1 = 1
{% if from_expr %}AND order_date >= {{ from_expr }}{% endif %}
{% if to_expr %}AND order_date < {{ to_expr }}{% endif %}': The query contains one or more malformed
template parameters.
Please check your query and confirm that all template parameters are surround by double braces, for
example, "{{ ds }}". Then, try running your query again.
Screenshots/recordings
No response
Superset version
4.1.2
Python version
3.11
Node version
16
Browser
Chrome
Additional context
No response
Checklist
- [x] 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.
Comment From: dosubot[bot]
To resolve the "Parameter error" in your Jinja SQL query, ensure that all template parameters are correctly defined and match the parameters set in the "Set Parameters" section. The error message suggests checking for syntax errors and ensuring parameter names are consistent across your SQL query and the parameters you have set.
Make sure that all template parameters are surrounded by double braces, for example, {{ ds }}
. This is crucial for the correct interpretation of the parameters in the query.
Here's a relevant excerpt from the code that handles this:
PARAMETER_MISSING_ERR = __(
"Please check your template parameters for syntax errors and make sure "
"they match across your SQL query and Set Parameters. Then, try running "
"your query again."
)
The _validate
method checks for undefined parameters:
def _validate(
self,
execution_context: SqlJsonExecutionContext,
rendered_query: str,
sql_template_processor: BaseTemplateProcessor,
) -> None:
if is_feature_enabled("ENABLE_TEMPLATE_PROCESSING"):
syntax_tree = sql_template_processor.env.parse(rendered_query)
undefined_parameters = find_undeclared_variables(syntax_tree)
if undefined_parameters:
self._raise_undefined_parameter_exception(
execution_context, undefined_parameters
)
Ensure that all parameters used in your query are declared and match the parameters provided in the execution context. If there are any undeclared variables, they will trigger an error. Also, double-check your query for any syntax errors near the reported error location [1][2].
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
Comment From: rusackas
Hopefully the bot helped, thus the silence. If not, please provide a more meaningful title to the issue, and some reproduction steps we can follow, if this is still an issue in 5.0.0, and we'll be more than happy to reopen.