apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
62.64k stars 13.83k forks source link

SQL_QUERY_MUTATOR not called in SQLab with MUTATE_AFTER_SPLIT = True #30169

Open dmarkey opened 2 months ago

dmarkey commented 2 months ago

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

dosubot[bot] commented 2 months ago

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.