mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(template_processing): get_filters now works for IS_NULL and IS_NOT_NULL operators (#33296)
This commit is contained in:
@@ -404,7 +404,15 @@ class ExtraCache:
|
||||
flt.get("expressionType") == "SIMPLE"
|
||||
and flt.get("clause") == "WHERE"
|
||||
and flt.get("subject") == column
|
||||
and val
|
||||
and (
|
||||
val
|
||||
# IS_NULL and IS_NOT_NULL operators do not have a value
|
||||
or op
|
||||
in (
|
||||
FilterOperator.IS_NULL.value,
|
||||
FilterOperator.IS_NOT_NULL.value,
|
||||
)
|
||||
)
|
||||
):
|
||||
if remove_filter:
|
||||
if column not in self.removed_filters:
|
||||
|
||||
@@ -220,6 +220,36 @@ def test_get_filters_adhoc_filters() -> None:
|
||||
assert cache.applied_filters == ["name"]
|
||||
|
||||
|
||||
def test_get_filters_is_null_operator() -> None:
|
||||
"""
|
||||
Test the ``get_filters`` macro with a IS_NULL operator,
|
||||
which doesn't have a comparator
|
||||
"""
|
||||
with app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
"adhoc_filters": [
|
||||
{
|
||||
"clause": "WHERE",
|
||||
"expressionType": "SIMPLE",
|
||||
"operator": "IS NULL",
|
||||
"subject": "name",
|
||||
"comparator": None,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
}
|
||||
):
|
||||
cache = ExtraCache()
|
||||
assert cache.get_filters("name", remove_filter=True) == [
|
||||
{"op": "IS NULL", "col": "name", "val": None}
|
||||
]
|
||||
assert cache.removed_filters == ["name"]
|
||||
assert cache.applied_filters == ["name"]
|
||||
|
||||
|
||||
def test_get_filters_remove_not_present() -> None:
|
||||
"""
|
||||
Test the ``get_filters`` macro without a match and ``remove_filter`` set to True.
|
||||
|
||||
Reference in New Issue
Block a user