dosubot[bot] commented on issue #30168:
URL: https://github.com/apache/superset/issues/30168#issuecomment-3496760538
<!-- Answer -->
You can define SQL_QUERY_MUTATOR in superset_config.py by writing a Python
function that takes the SQL string as its first argument and includes **kwargs
for compatibility. Assign your function to the SQL_QUERY_MUTATOR variable. For
example:
```python
def SQL_QUERY_MUTATOR(sql, security_manager=None, database=None, **kwargs):
# Example: add a comment with the current user ID
from superset.utils.core import get_user_id
user_id = get_user_id()
return f"-- User ID: {user_id}\n{sql}"
SQL_QUERY_MUTATOR = SQL_QUERY_MUTATOR
```
Make sure your function always includes **kwargs so it stays compatible with
future Superset updates. If you want the mutator to run after splitting
multi-statement queries, set:
```python
MUTATE_AFTER_SPLIT = True
```
You can use either a regular function or a lambda. The mutator should be
deterministic since its output doesn't affect the cache key. More details and
examples are in the Superset config and tests
([config.py](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/config.py#L1391-L1421),
[model_tests.py](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/tests/integration_tests/model_tests.py#L523-L556)).
<!-- 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/bef85ca9-7ca1-43a8-91af-6689eeb3dd3e?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/bef85ca9-7ca1-43a8-91af-6689eeb3dd3e?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/bef85ca9-7ca1-43a8-91af-6689eeb3dd3e?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/bef85ca9-7ca1-43a8-91af-6689eeb3dd3e?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/bef85ca9-7ca1-43a8-91af-6689eeb3dd3e?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/bef85ca9-7ca1-43a8-91af-6689eeb3dd3e?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/bef85ca9-7ca1-43a8-91af-6689eeb3dd3e?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=githu
b) [](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/issues/30168)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]