Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ def search_table(table: Any, value: Any, column: str) -> list[Any]:
return []

results: list[Any] = []
search_value = str(value).lower() if value else ""
# Only Blank (None) and "" mean "no search value, return every row"; a
# falsy 0 or False is still the value the caller asked to match.
search_value = str(value).lower() if value is not None else ""

for item in cast(list[Any], table):
item_value: Any = None
Expand Down
12 changes: 12 additions & 0 deletions python/packages/declarative/tests/test_powerfx_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,15 @@ def test_search_table_empty_value(self):
result = search_table(items, "", "name")
# Empty string matches everything
assert len(result) == 2

def test_search_table_zero_is_a_value_not_a_blank(self):
"""Test search_table with a numeric zero."""
items = [{"code": 0}, {"code": 10}, {"code": 2}]
assert [item["code"] for item in search_table(items, 0, "code")] == [0, 10]
# Blank still means "match everything".
assert [item["code"] for item in search_table(items, None, "code")] == [0, 10, 2]

def test_search_table_false_is_a_value_not_a_blank(self):
"""Test search_table with a boolean False."""
items = [{"ok": True, "label": "yes"}, {"ok": False, "label": "no"}]
assert [item["label"] for item in search_table(items, False, "ok")] == ["no"]
Loading