Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
13 changes: 13 additions & 0 deletions python/packages/duckdb/tests/duckdb/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 18 additions & 0 deletions python/packages/postgres/tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading