apache/superset · error · QueryObjectValidationError
Error in jinja expression in column expression: %(msg)s
Error message
Error in jinja expression in column expression: %(msg)s
What it means
QueryObjectValidationError raised in TableColumn.get_sqla_col (models.py:1214) when Jinja processing of a stored column expression throws SupersetSyntaxErrorException. Columns with a SQL expression (calculated columns) are rendered through the sandboxed template processor before being embedded in the query; template syntax errors, sandbox violations, or undefined variables in that expression surface here with the underlying message.
Source
Thrown at superset/connectors/sqla/models.py:1214
self.db_engine_spec.engine,
)
def get_sqla_col(
self,
label: str | None = None,
template_processor: BaseTemplateProcessor | None = None,
) -> Column:
label = label or self.column_name
db_engine_spec = self.db_engine_spec
column_spec = db_engine_spec.get_column_spec(self.type, db_extra=self.db_extra)
type_ = column_spec.sqla_type if column_spec else None
if expression := self.expression:
if template_processor:
try:
expression = template_processor.process_template(expression)
except SupersetSyntaxErrorException as ex:
msg = str(ex)
raise QueryObjectValidationError(
_(
"Error in jinja expression in column expression: %(msg)s",
msg=msg,
)
) from ex
if expression != self.expression:
# Re-check the rendered expression before embedding it.
expression = validate_rendered_expression(
expression,
self.database,
self.table.catalog if self.table else None,
self.table.schema if self.table else None,
)
expression = self._validate_stored_expression(expression)
col = literal_column(expression, type_=type_)
else:
col = column(self.column_name, type_=type_)
col = self.database.make_sqla_column_compatible(col, label)View on GitHub (pinned to f4587218dd)
Solutions
- Open the dataset editor, edit the calculated column, and fix the Jinja (use |default guards so it renders with no runtime filter context).
- Test the same Jinja in Explore's chart with the filters applied to confirm it renders.
- Check the %(msg)s in the error for the precise Jinja failure (undefined name, syntax, security).
- For scheduled contexts (reports/alerts), avoid macros that depend on dashboard runtime filters.
Example fix
-- before (calculated column expression)
{{ calc_value(filter_values('region')) }}
-- after
{{ calc_value(filter_values('region') | default(['ALL'], true)) }} Defensive patterns
Strategy: try-catch
Validate before calling
from jinja2.sandbox import SandboxedEnvironment
def expression_renders(expression: str, context: dict | None = None) -> bool:
try:
SandboxedEnvironment().from_string(expression).render(context or {})
return True
except Exception:
return False Try / catch
from superset.exceptions import QueryObjectValidationError
try:
sqla_col = table_column.get_sqla_col(template_processor=processor)
except QueryObjectValidationError as ex:
if "column expression" in str(ex):
log_dataset_issue(dataset_id, ex)
raise Prevention
- Default-guard all filter-dependent macros in calculated columns.
- Test calculated columns in headless contexts (report render), not just interactive Explore.
- Render-test dataset expressions with an empty context in CI.
When it happens
Trigger: A dataset calculated column whose expression contains Jinja ({{ ... }} or {% ... %}) that fails to render at query time — e.g. {{ filter_values('x')[0] }} when no such filter exists, malformed {{, or a blocked construct. Triggered by any chart query selecting that column.
Common situations: Calculated column authored with macros that assume dashboard filters not present in a scheduled report/alert context; typos in Jinja; Jinja sandbox tightened after upgrade rejecting previously allowed filters.
Related errors
- Error in jinja expression in datetime column: %(msg)s
- Error in jinja expression in metric expression: %(msg)s
- Dataset metric not found.
- Error in jinja expression in RLS filters: %(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/2d80bc5e1aa3e8e0.
Report an issue: GitHub.