Skip to content

PYTHON-5046 Support $lookup in CSFLE and QE #2210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 1 addition & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PyMongo 4.12 brings a number of changes including:

- Support for configuring DEK cache lifetime via the ``key_expiration_ms`` argument to
:class:`~pymongo.encryption_options.AutoEncryptionOpts`.
- Support for $lookup in CSFLE and QE.pr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QE.pr -> QE supported on MongoDB 8.1+.


Issues Resolved
...............
Expand Down
10 changes: 4 additions & 6 deletions pymongo/asynchronous/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
)
raise exc from final_err

async def collection_info(self, database: str, filter: bytes) -> Optional[bytes]:
async def collection_info(self, database: str, filter: bytes) -> Optional[list[bytes]]:
"""Get the collection info for a namespace.

The returned collection info is passed to libmongocrypt which reads
Expand All @@ -251,14 +251,12 @@ async def collection_info(self, database: str, filter: bytes) -> Optional[bytes]
:param database: The database on which to run listCollections.
:param filter: The filter to pass to listCollections.

:return: The first document from the listCollections command response as BSON.
:return: The all documents from the listCollections command response as BSON.
Copy link
Member

@ShaneHarvey ShaneHarvey Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The all documents" -> "All documents"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oop good catch, fixed!

"""
async with await self.client_ref()[database].list_collections(
filter=RawBSONDocument(filter)
) as cursor:
async for doc in cursor:
return _dict_to_bson(doc, False, _DATA_KEY_OPTS)
return None
return [_dict_to_bson(doc, False, _DATA_KEY_OPTS) async for doc in cursor]

def spawn(self) -> None:
"""Spawn mongocryptd.
Expand Down Expand Up @@ -551,7 +549,7 @@ def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions:
# For compat with pymongocrypt <1.13, avoid setting the default key_expiration_ms.
if kwargs.get("key_expiration_ms") is None:
kwargs.pop("key_expiration_ms", None)
return MongoCryptOptions(**kwargs)
return MongoCryptOptions(**kwargs, enable_multiple_collinfo=True)


class AsyncClientEncryption(Generic[_DocumentType]):
Expand Down
10 changes: 4 additions & 6 deletions pymongo/synchronous/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
)
raise exc from final_err

def collection_info(self, database: str, filter: bytes) -> Optional[bytes]:
def collection_info(self, database: str, filter: bytes) -> Optional[list[bytes]]:
"""Get the collection info for a namespace.

The returned collection info is passed to libmongocrypt which reads
Expand All @@ -250,12 +250,10 @@ def collection_info(self, database: str, filter: bytes) -> Optional[bytes]:
:param database: The database on which to run listCollections.
:param filter: The filter to pass to listCollections.

:return: The first document from the listCollections command response as BSON.
:return: The all documents from the listCollections command response as BSON.
"""
with self.client_ref()[database].list_collections(filter=RawBSONDocument(filter)) as cursor:
for doc in cursor:
return _dict_to_bson(doc, False, _DATA_KEY_OPTS)
return None
return [_dict_to_bson(doc, False, _DATA_KEY_OPTS) for doc in cursor]

def spawn(self) -> None:
"""Spawn mongocryptd.
Expand Down Expand Up @@ -548,7 +546,7 @@ def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions:
# For compat with pymongocrypt <1.13, avoid setting the default key_expiration_ms.
if kwargs.get("key_expiration_ms") is None:
kwargs.pop("key_expiration_ms", None)
return MongoCryptOptions(**kwargs)
return MongoCryptOptions(**kwargs, enable_multiple_collinfo=True)


class ClientEncryption(Generic[_DocumentType]):
Expand Down
Loading
Loading