Skip to content

Commit 76e93b6

Browse files
committed
fix(python): address negative filter review regressions
Narrow numeric constants with isinstance while keeping bool excluded. Replace the obsolete Postgres negative-integer rejection with successful negative bound, equality and float parameter cases. Prepared with AI assistance and independently reviewed. Fresh validation: 232 data/Postgres/Chroma/Qdrant unit tests passed; mypy passed for all 556 semantic_kernel source files; Ruff lint and format checks passed for both changed files. Full repository tests and live-service integration tests were not run.
1 parent 979154a commit 76e93b6

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎python/semantic_kernel/data/vector.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ def visit_UnaryOp(self, node: UnaryOp) -> AST:
729729
if (
730730
isinstance(node.op, USub)
731731
and isinstance(node.operand, Constant)
732-
and type(node.operand.value) in (int, float)
732+
and isinstance(node.operand.value, (int, float))
733+
and not isinstance(node.operand.value, bool)
733734
):
734735
return copy_location(Constant(-node.operand.value), node)
735736
return node

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ class FilterRecord:
372372
("x.id == 1", '"id" = %s', [1]),
373373
("x.id != 1", '"id" <> %s', [1]),
374374
("x.id > 1", '"id" > %s', [1]),
375+
("x.id > -1", '"id" > %s', [-1]),
376+
("x.id == -1", '"id" = %s', [-1]),
377+
("x.id == -1.5", '"id" = %s', [-1.5]),
375378
("x.id >= 1", '"id" >= %s', [1]),
376379
("x.id < 1", '"id" < %s', [1]),
377380
("x.id <= 1", '"id" <= %s', [1]),
@@ -502,7 +505,6 @@ def test_filter_identifier_quoting(filter_collection):
502505
("1j != None", VectorStoreOperationException),
503506
("x.id is None", NotImplementedError),
504507
("x.id is not None", NotImplementedError),
505-
("x.id == -1", NotImplementedError),
506508
("x.id == +1", NotImplementedError),
507509
("x.id == ~1", NotImplementedError),
508510
("x.tenant.startswith('a')", NotImplementedError),

0 commit comments

Comments
 (0)