Skip to content
Open
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
2 changes: 1 addition & 1 deletion python/semantic_kernel/data/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def default_dynamic_filter_function(
new_filter = None
if param.name in kwargs:
new_filter = f"lambda x: x.{param.name} == {_format_filter_literal(kwargs[param.name])}"
elif param.default_value:
elif param.default_value is not None:
new_filter = f"lambda x: x.{param.name} == {_format_filter_literal(param.default_value)}"
if not new_filter:
continue
Expand Down
26 changes: 26 additions & 0 deletions python/tests/unit/data/test_text_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ async def test_create_kernel_function_inner_with_options(kernel: Kernel):
assert results.value == ["test"]


@pytest.mark.parametrize(("default_value", "expected_literal"), [(0, "0"), (False, "False"), ("", "''")])
async def test_create_kernel_function_applies_falsy_filter_defaults(
kernel: Kernel, default_value: int | bool | str, expected_literal: str
):
test_search = TestSearch()
kernel_function = test_search.create_search_function(
parameters=[
KernelParameterMetadata(
name="category",
description="Category filter.",
type=type(default_value).__name__,
is_required=False,
default_value=default_value,
type_object=type(default_value),
)
]
)

with patch.object(test_search, "search", wraps=test_search.search) as mock_search:
await kernel_function.invoke(kernel)

mock_search.assert_awaited_once_with(
query="", output_type=str, filter=f"lambda x: x.category == {expected_literal}"
)


async def test_create_kernel_function_inner_with_other_options_type(kernel: Kernel):
test_search = TestSearch()

Expand Down
Loading