{"record":{"id":"a513c61ab92096ea","repo":"apache/superset","slug":"error-in-jinja-expression-in-fetch-values-predicat","errorCode":null,"errorMessage":"Error in jinja expression in fetch values predicate: %(msg)s","messagePattern":"Error in jinja expression in fetch values predicate: (.+?)","errorType":"validation","errorClass":"QueryObjectValidationError","httpStatus":400,"severity":"error","filePath":"superset/connectors/sqla/models.py","lineNumber":1829,"sourceCode":"            validate_stored_expression(\n                self.database, self.catalog, self.schema, fetch_values_predicate\n            )\n            return self.text(fetch_values_predicate)\n        except (SupersetSecurityException, QueryClauseValidationException) as ex:\n            message = (\n                ex.error.message\n                if isinstance(ex, SupersetSecurityException)\n                else ex.message\n            )\n            raise QueryObjectValidationError(\n                _(\n                    \"Fetch values predicate failed SQL validation: %(msg)s\",\n                    msg=message,\n                )\n            ) from ex\n        except (TemplateError, SupersetSyntaxErrorException) as ex:\n            msg = getattr(ex, \"message\", str(ex))\n            raise QueryObjectValidationError(\n                _(\n                    \"Error in jinja expression in fetch values predicate: %(msg)s\",\n                    msg=msg,\n                )\n            ) from ex\n\n    def get_template_processor(self, **kwargs: Any) -> BaseTemplateProcessor:\n        return get_template_processor(table=self, database=self.database, **kwargs)\n\n    def get_sqla_table(self) -> TableClause:\n        # For databases that support cross-catalog queries (like BigQuery),\n        # include the catalog in the table identifier to generate\n        # project.dataset.table format\n        if self.catalog and self.database.db_engine_spec.supports_cross_catalog_queries:\n            # SQLAlchemy doesn't have built-in catalog support for TableClause,\n            # so we need to construct the full identifier manually with proper quoting\n            catalog_quoted = self.quote_identifier(self.catalog)\n            table_quoted = self.quote_identifier(self.table_name)","sourceCodeStart":1811,"sourceCodeEnd":1847,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/connectors/sqla/models.py#L1811-L1847","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"-- before (fetch_values_predicate)\ncol IN {{ filter_values('col') }\n\n-- after\ncol IN ({{ \"'\" ~ (filter_values('col') | default(['x'], true) | join(\"','\")) ~ \"'\" }})","handlingStrategy":"try-catch","validationCode":"from jinja2.sandbox import SandboxedEnvironment\n\ndef predicate_template_valid(predicate: str) -> bool:\n    try:\n        SandboxedEnvironment().from_string(predicate).render({})\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"from superset.exceptions import QueryObjectValidationError\n\ntry:\n    predicate = table.get_fetch_values_predicate(template_processor=processor)\nexcept QueryObjectValidationError as ex:\n    if \"fetch values predicate\" in str(ex) and \"jinja\" in str(ex).lower():\n        flag_dataset_template_error(table.id, ex)\n    raise","preventionTips":["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."],"tags":["jinja","fetch-values-predicate","template","superset"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}