Bug description
SQL_QUERY_MUTATOR
function is not called for queries in SQLab when MUTATE_AFTER_SPLIT = True
Simply not called, but is called when MUTATE_AFTER_SPLIT = False
How to reproduce the bug
config.py:
MUTATE_AFTER_SPLIT = True
def SQL_QUERY_MUTATOR( # pylint: disable=invalid-name,unused-argument
sql: str, **kwargs
) -> str:
print("Query mutator called") ## will not print during SQLab sessions
return sql
Navigate to SQLLab and do some queries.. see nothing printed..
Go to a chart and see the print message.
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.9
Node version
18 or greater
Browser
Chrome
Additional context
No response
Checklist
- [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [X] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Comment From: dosubot[bot]
The SQL_QUERY_MUTATOR
function is not called in SQLab when MUTATE_AFTER_SPLIT = True
because the condition for calling the mutator function checks if the is_split
parameter matches the MUTATE_AFTER_SPLIT
configuration. If MUTATE_AFTER_SPLIT
is set to True
, the mutator function will only be called after the SQL is split into smaller queries. If the SQL is not split, the condition will not be met, and the mutator function will not be called.
Here is the relevant code snippet:
sql_mutator = config["SQL_QUERY_MUTATOR"]
if sql_mutator and (is_split == config["MUTATE_AFTER_SPLIT"]):
return sql_mutator(
sql_,
security_manager=security_manager,
database=self,
)
return sql_
In this code, is_split
must be True
for the mutator to be called when MUTATE_AFTER_SPLIT
is True
. If is_split
is False
, the mutator will not be invoked [1][2].
To continue talking to Dosu, mention @dosu.
Comment From: rusackas
@dmarkey is this something you're still facing in current versions?
Comment From: rusackas
Looks like there's quite a bit of discussion on the linked PR. Anyone interested in this issue should take things up on that thread, and help us come to a conclusion there :)