{"record":{"id":"d7dee27ae435ceb8","repo":"apache/superset","slug":"error-in-jinja-expression-in-rls-filters-msg-s","errorCode":null,"errorMessage":"Error in jinja expression in RLS filters: %(msg)s","messagePattern":"Error in jinja expression in RLS filters: (.+?)","errorType":"validation","errorClass":"QueryObjectValidationError","httpStatus":400,"severity":"error","filePath":"superset/connectors/sqla/models.py","lineNumber":902,"sourceCode":"                    filter_groups[filter_.group_key].append(clause)\n                else:\n                    all_filters.append(clause)\n\n            if is_feature_enabled(\"EMBEDDED_SUPERSET\"):\n                for rule in security_manager.get_guest_rls_filters(self):\n                    if not include_global_guest_rls and not rule.get(\"dataset\"):\n                        continue\n                    clause = self.text(\n                        f\"({template_processor.process_template(rule['clause'])})\"\n                    )\n                    all_filters.append(clause)\n\n            grouped_filters = [or_(*clauses) for clauses in filter_groups.values()]\n            all_filters.extend(grouped_filters)\n            return all_filters\n        except (TemplateError, SupersetSyntaxErrorException) as ex:\n            msg = getattr(ex, \"message\", str(ex))\n            raise QueryObjectValidationError(\n                _(\n                    \"Error in jinja expression in RLS filters: %(msg)s\",\n                    msg=msg,\n                )\n            ) from ex\n\n\nclass AnnotationDatasource(BaseDatasource):\n    \"\"\"Dummy object so we can query annotations using 'Viz' objects just like\n    regular datasources.\n    \"\"\"\n\n    cache_timeout = 0\n    changed_on = None\n    type = \"annotation\"\n    column_names = [\n        \"created_on\",\n        \"changed_on\",","sourceCodeStart":884,"sourceCodeEnd":920,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/connectors/sqla/models.py#L884-L920","documentation":"QueryObjectValidationError wrapping a Jinja TemplateError or SupersetSyntaxErrorException raised while rendering row-level-security rule clauses in SqlaTable.get_sqla_row_level_filters (models.py:902). Each RLS rule's clause string is processed through the Jinja sandbox template processor before being embedded as a SQL predicate; malformed template syntax or disallowed sandbox constructs abort the query.","triggerScenarios":"A dataset with an RLS rule (regular or dataset-scoped) whose clause contains invalid Jinja (e.g. unclosed {{, undefined filter, a blocked filter like {{ subprocess }}), executed whenever a query runs against a table for which the RLS rule applies to the current user's roles.","commonSituations":"Admin edits an RLS clause and introduces a typo; Jinja context differs between Explore and SQL Lab so macros valid elsewhere are undefined under RLS; copying a clause from a dashboard filter that references unavailable variables; upgrades that tighten the Jinja sandbox.","solutions":["Open Settings > Row Level Security, locate the failing rule for the dataset/roles, and fix the Jinja in its clause (test it separately in Explore with the same macros).","Only use macros guaranteed in the query context (filter_values, url_param, current_username, etc.) and guard with default filters: {{ filter_values('x') | default([], true) }}.","Check Superset logs for the underlying message (%(msg)s) — it names the exact template line/error.","If the rule is not needed for the affected roles, remove the group/role from the rule's GroupKey so it stops applying."],"exampleFix":"-- before (RLS clause)\ncountry = '{{ filter_values('country') }}'\n\n-- after (guard against undefined/empty and malformed Jinja)\ncountry IN ({{ \"'\" ~ filter_values('country') | join(\"','\") ~ \"'\" if filter_values('country') else \"country\" }})","handlingStrategy":"try-catch","validationCode":"from jinja2.sandbox import SandboxedEnvironment\n\ndef rls_clause_renders(clause: str) -> bool:\n    env = SandboxedEnvironment()\n    try:\n        env.from_string(clause).render({})\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"from superset.exceptions import QueryObjectValidationError\n\ntry:\n    df = query_context.get_df()\nexcept QueryObjectValidationError as ex:\n    if \"RLS filters\" in str(ex):\n        # surface to admins: an RLS rule is broken, not the chart\n        notify_admins(f\"Broken RLS rule: {ex}\")\n        raise","preventionTips":["Lint RLS clauses with a Jinja sandbox render in CI before saving rules.","Only use macros guaranteed available in RLS context; default-guard everything.","Keep RLS clause edits behind review; a typo breaks every query for affected roles."],"tags":["rls","jinja","security","superset"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}