From 58329c442512090a10c518873423a2440e123fad Mon Sep 17 00:00:00 2001 From: "Grapette.L" <90967079+Lesereingrape@users.noreply.github.com> Date: Fri, 2 Oct 2026 19:46:03 +0800 Subject: [PATCH] Python: Search() keeps a falsy value instead of treating it as Blank search_table built its needle with `if value else`, so a numeric 0, 0.0 or False became "" and matched every row: Search(rows, 0, "code") returned the whole table while Search(rows, "0", "code") returned the two matching rows. Power Fx only treats Blank as match-all, and the rest of this module already guards with `is not None`, so use that here and keep None and "" matching everything. --- .../_workflows/_powerfx_functions.py | 4 +++- .../declarative/tests/test_powerfx_functions.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/packages/declarative/agent_framework_declarative/_workflows/_powerfx_functions.py b/python/packages/declarative/agent_framework_declarative/_workflows/_powerfx_functions.py index eba3be4ea75..e5b2f4156d0 100644 --- a/python/packages/declarative/agent_framework_declarative/_workflows/_powerfx_functions.py +++ b/python/packages/declarative/agent_framework_declarative/_workflows/_powerfx_functions.py @@ -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 diff --git a/python/packages/declarative/tests/test_powerfx_functions.py b/python/packages/declarative/tests/test_powerfx_functions.py index a0b0ce1e0a7..239303794cf 100644 --- a/python/packages/declarative/tests/test_powerfx_functions.py +++ b/python/packages/declarative/tests/test_powerfx_functions.py @@ -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"]