Skip to content

Commit 5377800

Browse files
Python: Cover callable and mixed Postgres search filters (#14313)
Postgres search filters must produce SQL predicates with their values passed separately as ordered parameters. Extend the search execution tests to cover callable filters, single-item and empty lists, and mixed string/callable lists, including OR grouping, across all five supported distance functions and both result-consumption paths. The parameterized connector implementation from #14497 is preserved. The diff against main is limited to test coverage and adds 30 cases. Related to #14311. Validation on Python 3.12: - Postgres connector unit tests: 127 passed. - Shared data/vector unit tests: 76 passed. - Repository pre-commit checks for the Postgres connector and test file: passed, including Ruff, formatting, Python syntax, pyupgrade, and Bandit. The tests inspect the SQL and ordered parameters passed to the mocked Postgres cursor; no live database is required. Co-authored-by: Eduard van Valkenburg <[email protected]>
1 parent 2281d4d commit 5377800

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

‎python/tests/unit/connectors/memory/test_postgres_store.py‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import ast
44
import asyncio
5-
from collections.abc import AsyncGenerator
5+
from collections.abc import AsyncGenerator, Callable
66
from dataclasses import dataclass
77
from datetime import date
88
from decimal import Decimal
@@ -382,12 +382,32 @@ async def test_get_records(vector_store: PostgresStore, mock_cursor: Mock) -> No
382382
"filter, filter_sql, filter_params",
383383
[
384384
(None, "", []),
385+
([], "", []),
385386
("lambda x: x.id == 1", ' WHERE ("id" = %s)', [1]),
387+
(lambda x: x.id == 1, ' WHERE ("id" = %s)', [1]),
388+
(["lambda x: x.id == 1"], ' WHERE ("id" = %s)', [1]),
389+
([lambda x: x.id == 1], ' WHERE ("id" = %s)', [1]),
386390
(
387391
["lambda x: x.id > 0", "lambda x: x.id == 1 or x.id == 2"],
388392
' WHERE ("id" > %s) AND (("id" = %s OR "id" = %s))',
389393
[0, 1, 2],
390394
),
395+
(
396+
[
397+
lambda x: x.id > 0,
398+
lambda x: x.id == 1 or x.id == 2,
399+
],
400+
' WHERE ("id" > %s) AND (("id" = %s OR "id" = %s))',
401+
[0, 1, 2],
402+
),
403+
(
404+
[
405+
"lambda x: x.id > 0",
406+
lambda x: x.id == 1 or x.id == 2,
407+
],
408+
' WHERE ("id" > %s) AND (("id" = %s OR "id" = %s))',
409+
[0, 1, 2],
410+
),
391411
],
392412
)
393413
@pytest.mark.parametrize(
@@ -408,7 +428,7 @@ async def test_vector_search(
408428
subquery_distance: str | None,
409429
include_vectors: bool,
410430
include_total_count: bool,
411-
filter: str | list[str] | None,
431+
filter: str | Callable | list[str | Callable] | None,
412432
filter_sql: str,
413433
filter_params: list[Any],
414434
) -> None:

0 commit comments

Comments
 (0)