GitHub user dosubot[bot] added a comment to the discussion: Set database transaction params
<!-- Answer --> Your set_rls_context handler isn't being called because Superset v5 doesn't support a DB_ENGINE_MUTATOR hook that attaches SQLAlchemy event listeners like "begin" to the engine. The only supported engine mutator is DB_CONNECTION_MUTATOR, which is used to mutate connection parameters before engine creation—not to inject per-query or per-transaction logic. Superset's query execution flow doesn't wire in user-provided event listeners, so your approach won't trigger the handler as you expect ([reference](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/config.py#L1345-L1412)). If you need to inject session variables per query (for RLS), the only viable path is to use SQL_QUERY_MUTATOR to prepend SET LOCAL statements to the SQL. However, integrating this with guest_token claims requires custom logic to extract those claims and inject them into the SQL string. There’s no built-in way to do this per user/session in embedded scenarios ([reference](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/config.py#L1345-L1412)). Let me know if you want guidance on implementing a custom SQL_QUERY_MUTATOR for this use case. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/5aaf22c8-bb60-4dc3-bdc4-670c768f9c4c?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5aaf22c8-bb60-4dc3-bdc4-670c768f9c4c?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5aaf22c8-bb60-4dc3-bdc4-670c768f9c4c?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5aaf22c8-bb60-4dc3-bdc4-670c768f9c4c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5aaf22c8-bb60-4dc3-bdc4-670c768f9c4c?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5aaf22c8-bb60-4dc3-bdc4-670c768f9c4c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5aaf22c8-bb60-4dc3-bdc4-670c768f9c4c?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github) [](https://cursor.com/link/prompt?text=Your%20set_rls_context%20handler%20isn%27t%20being%20called%20because%20Superset%20v5%20doesn%27t%20support%20a%20DB_ENGINE_MUTATOR%20hook%20that%20attaches%20SQLAlchemy%20event%20listeners%20like%20%22begin%22%20to%20the%20engine.%20The%20only%20supported%20engine%20mutator%20is%20DB_CONNECTION_MUTATOR%2C%20which%20is%20used%20to%20mutate%20connection%20parameters%20before%20engine%20creation%E2%80%94not%20to%20inject%20per-query%20or%20per-transaction%20logic.%20Superset%27s%20query%20execution%20flow%20doesn%27t%20wire%20in%20user-provided%20event%20listeners%2C%20so%20your%20approach%20won%27t%20trigger%20the%20handler%20as%20you%20expect%20%28%5Breference%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/supe rset/config.py%23L1345-L1412%29%29.%0A%0AIf%20you%20need%20to%20inject%20session%20variables%20per%20query%20%28for%20RLS%29%2C%20the%20only%20viable%20path%20is%20to%20use%20SQL_QUERY_MUTATOR%20to%20prepend%20SET%20LOCAL%20statements%20to%20the%20SQL.%20However%2C%20integrating%20this%20with%20guest_token%20claims%20requires%20custom%20logic%20to%20extract%20those%20claims%20and%20inject%20them%20into%20the%20SQL%20string.%20There%E2%80%99s%20no%20built-in%20way%20to%20do%20this%20per%20user/session%20in%20embedded%20scenarios%20%28%5Breference%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/config.py%23L1345-L1412%29%29.%20%0A%0ALet%20me%20know%20if%20you%20want%20guidance%20on%20implementing%20a%20custom%20SQL_QUERY_MUTATOR%20for%20this%20use%20case.) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/37498) GitHub link: https://github.com/apache/superset/discussions/37498#discussioncomment-15641710 ---- 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]
