-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore!: update mutator to take kwargs #19083
Changes from all commits
290fbb3
3e5fc66
3bc6de0
2e02f7f
94065f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -506,7 +506,7 @@ def test_sql_mutator(self): | |
sql = tbl.get_query_str(query_obj) | ||
self.assertNotIn("-- COMMENT", sql) | ||
|
||
def mutator(*args): | ||
def mutator(*args, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we write a better test for making sure the mutator properly takes the params? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hughhhh I added one more test to check that the database name is being passed in. LMK if you think more tests around that would be helpful. |
||
return "-- COMMENT\n" + args[0] | ||
|
||
app.config["SQL_QUERY_MUTATOR"] = mutator | ||
|
@@ -515,6 +515,33 @@ def mutator(*args): | |
|
||
app.config["SQL_QUERY_MUTATOR"] = None | ||
|
||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") | ||
def test_sql_mutator_different_params(self): | ||
tbl = self.get_table(name="birth_names") | ||
query_obj = dict( | ||
groupby=[], | ||
metrics=None, | ||
filter=[], | ||
is_timeseries=False, | ||
columns=["name"], | ||
granularity=None, | ||
from_dttm=None, | ||
to_dttm=None, | ||
extras={}, | ||
) | ||
sql = tbl.get_query_str(query_obj) | ||
self.assertNotIn("-- COMMENT", sql) | ||
|
||
def mutator(sql, database=None, **kwargs): | ||
return "-- COMMENT\n--" + "\n" + str(database) + "\n" + sql | ||
|
||
app.config["SQL_QUERY_MUTATOR"] = mutator | ||
mutated_sql = tbl.get_query_str(query_obj) | ||
self.assertIn("-- COMMENT", mutated_sql) | ||
self.assertIn(tbl.database.name, mutated_sql) | ||
|
||
app.config["SQL_QUERY_MUTATOR"] = None | ||
|
||
def test_query_with_non_existent_metrics(self): | ||
tbl = self.get_table(name="birth_names") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qi, Is this assigning the existing user_name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the current user_name, or rather identifier. Sometimes it doesn't map directly to the person's name depending on how they've authenticated.