From 303692e12deb180cb645503226265ff974529928 Mon Sep 17 00:00:00 2001 From: Wilson0511 <1795618152@qq.com> Date: Mon, 9 Nov 2026 22:06:43 +0800 Subject: [PATCH] Reject skip with key lookup in PostgreSQL and DuckDB collections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit get(keys=..., skip=N) silently dropped the explicit skip in the PostgreSQL and DuckDB _inner_get key branches — the unshifted key query was built and run, so the same portable call succeeded here while MongoDB, Qdrant, and Oracle raise ValueError for it (and core itself raises for keys+filter as alternate retrieval modes). Both key branches now reject skip with the same message shape as their siblings, next to their existing order_by guard. Co-Authored-By: ZCode --- .../agent_framework_duckdb/_vector_store.py | 2 ++ .../duckdb/tests/duckdb/test_collection.py | 13 +++++++++++++ .../agent_framework_postgres/_vector_store.py | 2 ++ .../packages/postgres/tests/test_postgres.py | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/python/packages/duckdb/agent_framework_duckdb/_vector_store.py b/python/packages/duckdb/agent_framework_duckdb/_vector_store.py index fd7d5b5262e..a1234e32a96 100644 --- a/python/packages/duckdb/agent_framework_duckdb/_vector_store.py +++ b/python/packages/duckdb/agent_framework_duckdb/_vector_store.py @@ -602,6 +602,8 @@ async def _inner_get( if keys is not None: if order_by: raise ValueError("order_by applies only to filtered retrieval, not key lookup.") + if skip: + raise ValueError("DuckDB key retrieval cannot be combined with skip.") adapted = [_prepare_value(self.definition.key_field, key) for key in keys] if not adapted: return [] diff --git a/python/packages/duckdb/tests/duckdb/test_collection.py b/python/packages/duckdb/tests/duckdb/test_collection.py index 9d099f3b717..cd14f4ad67f 100644 --- a/python/packages/duckdb/tests/duckdb/test_collection.py +++ b/python/packages/duckdb/tests/duckdb/test_collection.py @@ -140,6 +140,19 @@ async def test_batch_crud_preserves_key_order_and_upserts(collection: DuckDBColl await collection.delete([]) +async def test_key_retrieval_rejects_skip(collection: DuckDBCollection[Any, Any]) -> None: + """skip with key lookup is rejected, not silently ignored. + + The other key-retrieval connectors (MongoDB, Qdrant, Oracle) raise for + skip+keys; silently ignoring it made the same portable call succeed on + DuckDB and fail elsewhere. + """ + with pytest.raises(ValueError, match="cannot be combined with skip"): + await collection.get(["first"], skip=1) + # skip stays valid for filtered listing + assert await collection.get(skip=1) == [] + + async def test_typed_model_roundtrips_and_searches(tmp_path): @vectorstoremodel(collection_name="articles") @dataclass diff --git a/python/packages/postgres/agent_framework_postgres/_vector_store.py b/python/packages/postgres/agent_framework_postgres/_vector_store.py index e4857cb5dbf..3e59715b7d6 100644 --- a/python/packages/postgres/agent_framework_postgres/_vector_store.py +++ b/python/packages/postgres/agent_framework_postgres/_vector_store.py @@ -723,6 +723,8 @@ async def _inner_get( if keys is not None: if order_by: raise ValueError("order_by applies only to filtered retrieval, not key lookup.") + if skip: + raise ValueError("PostgreSQL key retrieval cannot be combined with skip.") if not keys: return [] adapted = [self._prepare_key(key) for key in keys] diff --git a/python/packages/postgres/tests/test_postgres.py b/python/packages/postgres/tests/test_postgres.py index 0aa9671155a..32ae0a0ac6a 100644 --- a/python/packages/postgres/tests/test_postgres.py +++ b/python/packages/postgres/tests/test_postgres.py @@ -189,6 +189,24 @@ def test_order_names_and_directions_validated(collection): collection._prepare_order_by({"tags": True}) +async def test_key_retrieval_rejects_skip(definition_factory) -> None: + """skip with key lookup is rejected, not silently ignored (offline guard check). + + MongoDB, Qdrant and Oracle raise for skip+keys; PostgreSQL silently built + the unshifted key query instead, so the same portable call behaved + differently across connectors. + """ + collection = PostgresCollection( + dict, + definition=definition_factory(key_type="str"), + # connect_timeout keeps a pre-fix run (which reaches the connection + # layer instead of raising) failing fast rather than hanging + connection_string="host=unused connect_timeout=1", + ) + with pytest.raises(ValueError, match="cannot be combined with skip"): + await collection.get(["key-1"], skip=1) + + @pytest.mark.parametrize("key_type,value", [("int", True), ("int", "1"), ("UUID", 1), ("str", 1)]) async def test_keys_are_strict(definition_factory, record_factory, key_type, value): collection = PostgresCollection(