apache/superset · error · QueryObjectValidationError
Fetch values predicate failed SQL validation: %(msg)s
Error message
Fetch values predicate failed SQL validation: %(msg)s
What it means
QueryObjectValidationError raised in SqlaTable.get_fetch_values_predicate (models.py:1821) when the fetch_values_predicate SQL fails stored-expression validation (validate_stored_expression → SupersetSecurityException) or query clause validation (QueryClauseValidationException). The predicate is Jinja-rendered, then re-checked with the same sqlglot parser policy as column/metric expressions; if the rendered text is not a valid single expression, the query is aborted.
Source
Thrown at superset/connectors/sqla/models.py:1821
fetch_values_predicate = self.fetch_values_predicate
if template_processor:
fetch_values_predicate = template_processor.process_template(
fetch_values_predicate
)
try:
# Re-validate the rendered predicate with the same parser policy
# as stored column and metric expressions before embedding it.
validate_stored_expression(
self.database, self.catalog, self.schema, fetch_values_predicate
)
return self.text(fetch_values_predicate)
except (SupersetSecurityException, QueryClauseValidationException) as ex:
message = (
ex.error.message
if isinstance(ex, SupersetSecurityException)
else ex.message
)
raise QueryObjectValidationError(
_(
"Fetch values predicate failed SQL validation: %(msg)s",
msg=message,
)
) from ex
except (TemplateError, SupersetSyntaxErrorException) as ex:
msg = getattr(ex, "message", str(ex))
raise QueryObjectValidationError(
_(
"Error in jinja expression in fetch values predicate: %(msg)s",
msg=msg,
)
) from ex
def get_template_processor(self, **kwargs: Any) -> BaseTemplateProcessor:
return get_template_processor(table=self, database=self.database, **kwargs)
def get_sqla_table(self) -> TableClause:View on GitHub (pinned to f4587218dd)
Solutions
- Edit the dataset and make fetch_values_predicate a single valid SQL expression (no leading WHERE, no UNION; e.g. "country = 'US'").
- Guard Jinja so it always renders to valid SQL in all contexts (|default chains).
- Check the embedded %(msg)s from the wrapped SupersetSecurityException/QueryClauseValidationException for the parser's reason.
- Temporarily clear the predicate to confirm it is the source, then re-add incrementally.
Example fix
-- before (fetch_values_predicate)
WHERE country = '{{ filter_values('country')[0] }}'
-- after
country = '{{ filter_values('country') | default(['US'], true) | first }}' Defensive patterns
Strategy: validation
Validate before calling
from sqlglot import parse_one
from sqlglot.errors import ParseError
def fetch_values_predicate_valid(predicate: str) -> bool:
rendered_guarded = predicate # assume Jinja guarded upstream
try:
parse_one(f"SELECT {rendered_guarded}")
return True
except ParseError:
return False Try / catch
from superset.exceptions import QueryObjectValidationError
try:
predicate = table.get_fetch_values_predicate(template_processor=processor)
except QueryObjectValidationError as ex:
if "Fetch values predicate failed SQL validation" in str(ex):
log_dataset_config_error(table.id, ex)
raise Prevention
- Keep fetch_values_predicate a single SQL expression without leading WHERE.
- Guard its Jinja with defaults so it renders valid SQL in every context.
- Validate the predicate with sqlglot after test-rendering before saving the dataset.
When it happens
Trigger: Setting a fetch_values_predicate on a dataset whose SQL (after Jinja rendering) does not parse as a single SQL expression — e.g. renders to an empty string, contains a set operation, or has engine-invalid syntax — and then querying a chart that uses fetch values filtering.
Common situations: fetch_values_predicate with Jinja that renders empty when its filter is absent; predicate valid in one engine but queried under another; pasting a full WHERE clause (with the WHERE keyword) or multi-statement text into the field.
Related errors
- Dataset parameters are invalid.
- Dataset parameters are invalid.
- Dataset parameters are invalid.
- Cycle detected: {uuid} appears in its ancestry
- Duplicate UUID in folder structure: {uuid}
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/b7c918fb8443fd15.
Report an issue: GitHub.