apache/superset · error · QueryObjectValidationError
Error in jinja expression in fetch values predicate: %(msg)s
Error message
Error in jinja expression in fetch values predicate: %(msg)s
What it means
QueryObjectValidationError raised in SqlaTable.get_fetch_values_predicate (models.py:1829) when Jinja processing of fetch_values_predicate throws TemplateError or SupersetSyntaxErrorException (as opposed to failing SQL validation afterwards). The predicate string is a Jinja template; malformed template syntax, sandbox violations, or undefined variables stop rendering before SQL validation even runs.
Source
Thrown at superset/connectors/sqla/models.py:1829
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:
# For databases that support cross-catalog queries (like BigQuery),
# include the catalog in the table identifier to generate
# project.dataset.table format
if self.catalog and self.database.db_engine_spec.supports_cross_catalog_queries:
# SQLAlchemy doesn't have built-in catalog support for TableClause,
# so we need to construct the full identifier manually with proper quoting
catalog_quoted = self.quote_identifier(self.catalog)
table_quoted = self.quote_identifier(self.table_name)View on GitHub (pinned to f4587218dd)
Solutions
- Fix the Jinja syntax in the dataset's fetch_values_predicate (validate it renders standalone with the same macros).
- Use guarded defaults for any runtime-dependent values so rendering succeeds with no filter context.
- Inspect %(msg)s for the exact Jinja error class (TemplateSyntaxError, SecurityError, UndefinedError).
Example fix
-- before (fetch_values_predicate)
col IN {{ filter_values('col') }
-- after
col IN ({{ "'" ~ (filter_values('col') | default(['x'], true) | join("','")) ~ "'" }}) Defensive patterns
Strategy: try-catch
Validate before calling
from jinja2.sandbox import SandboxedEnvironment
def predicate_template_valid(predicate: str) -> bool:
try:
SandboxedEnvironment().from_string(predicate).render({})
return True
except Exception:
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" in str(ex) and "jinja" in str(ex).lower():
flag_dataset_template_error(table.id, ex)
raise Prevention
- Render-test fetch_values_predicate Jinja in the dataset editor before saving.
- Avoid sandbox-forbidden constructs in predicates.
- Treat predicate template errors as dataset config defects: fix the dataset, don't catch-and-ignore in charts.
When it happens
Trigger: A fetch_values_predicate containing invalid Jinja (unclosed {{, blocked filters, undefined macros) that raises while process_template runs, whenever a chart query on that dataset uses fetch-values predicates.
Common situations: Typos in the predicate's Jinja; macros referencing dashboard runtime context used in headless execution (reports, alerts, thumbnails); sandbox tightening across versions disallowing a filter that used to work.
Related errors
- Error in jinja expression in RLS filters: %(msg)s
- Error in jinja expression in column expression: %(msg)s
- Error in jinja expression in datetime column: %(msg)s
- Error in jinja expression in metric expression: %(msg)s
- Fetch values predicate failed SQL validation: %(msg)s
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/a513c61ab92096ea.
Report an issue: GitHub.