GitHub user baptisteaden added a comment to the discussion: Set database
transaction params
@dosu Yes can you help with the SQL_QUERY_MUTATOR? I tried this but it's not
called either:
```
def sql_query_mutator(sql, database, **kwargs):
print("🔥 RLS SET FROM G", flush=True)
if not has_request_context():
return sql
person_id = getattr(g, "app_person_id", None)
application_id = getattr(g, "app_application_id", None)
role = getattr(g, "app_role", None)
if not person_id:
return sql
# Escape values safely
def esc(val):
if val is None:
return "NULL"
return "'" + str(val).replace("'", "''") + "'"
rls_sql = f"""
SET LOCAL jwt.claims.person_id = {esc(person_id)};
SET LOCAL jwt.claims.application_id = {esc(application_id)};
SET LOCAL jwt.claims.role = {esc(role)};
"""
# Prepend RLS context before original query
return f"{rls_sql}\n{sql}"
SQL_QUERY_MUTATOR = sql_query_mutator
```
GitHub link:
https://github.com/apache/superset/discussions/37498#discussioncomment-15645313
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]