fix(template_processing): get_filters now works for IS_NULL and IS_NOT_NULL operators (#33296)

This commit is contained in:
Kasper Mol
2025-06-05 05:46:33 +02:00
committed by GitHub
parent edc60914f6
commit cc3460832f
2 changed files with 39 additions and 1 deletions

View File

@@ -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:

View File

@@ -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.