Fix bug where lists in queries cannot contain multiple types (#8032)

* use set instead of sorted to check equality of lists

* run black
This commit is contained in:
serenajiang 2019-08-13 13:06:44 -07:00 committed by Ville Brofeldt
parent 075b5a5d33
commit 17f0740692
2 changed files with 16 additions and 3 deletions

View File

@ -907,9 +907,7 @@ def merge_extra_filters(form_data: dict):
if isinstance(existing_filters[filter_key], list):
# Add filters for unequal lists
# order doesn't matter
if sorted(existing_filters[filter_key]) != sorted(
filtr["val"]
):
if set(existing_filters[filter_key]) != set(filtr["val"]):
form_data["adhoc_filters"].append(to_adhoc(filtr))
else:
form_data["adhoc_filters"].append(to_adhoc(filtr))

View File

@ -301,6 +301,7 @@ class UtilsTestCase(unittest.TestCase):
"extra_filters": [
{"col": "a", "op": "in", "val": "someval"},
{"col": "B", "op": "==", "val": ["c1", "c2"]},
{"col": "c", "op": "in", "val": ["c1", 1, None]},
],
"adhoc_filters": [
{
@ -317,6 +318,13 @@ class UtilsTestCase(unittest.TestCase):
"operator": "==",
"subject": "B",
},
{
"clause": "WHERE",
"comparator": ["c1", 1, None],
"expressionType": "SIMPLE",
"operator": "in",
"subject": "c",
},
],
}
expected = {
@ -335,6 +343,13 @@ class UtilsTestCase(unittest.TestCase):
"operator": "==",
"subject": "B",
},
{
"clause": "WHERE",
"comparator": ["c1", 1, None],
"expressionType": "SIMPLE",
"operator": "in",
"subject": "c",
},
]
}
merge_extra_filters(form_data)