Skip to content
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

MongoDB: Update adapter to pymongo 4.9 #278

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions cratedb_toolkit/adapter/pymongo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, dburi: str):
patch("pymongo.collection.Collection", collection_patched),
patch("pymongo.database.Collection", collection_patched),
# Converge a few low-level functions of PyMongo to no-ops.
patch("pymongo.mongo_client.MongoClient._ensure_session"),
patch("pymongo.mongo_client._ClientConnectionRetryable._get_server"),
patch("pymongo.synchronous.mongo_client.MongoClient._ensure_session"),
patch("pymongo.synchronous.mongo_client._ClientConnectionRetryable._get_server"),
]

def start(self):
Expand Down
15 changes: 8 additions & 7 deletions cratedb_toolkit/adapter/pymongo/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

import sqlalchemy as sa
from bson import SON
from pymongo import CursorType, helpers
from pymongo import CursorType, helpers_shared

Check warning on line 12 in cratedb_toolkit/adapter/pymongo/cursor.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/adapter/pymongo/cursor.py#L12

Added line #L12 was not covered by tests
from pymongo.client_session import ClientSession
from pymongo.collation import validate_collation_or_none
from pymongo.collection import Collection
from pymongo.common import validate_is_document_type, validate_is_mapping
from pymongo.cursor import _QUERY_OPTIONS, Cursor, _Hint, _Sort
from pymongo.cursor import Cursor
from pymongo.cursor_shared import _QUERY_OPTIONS, _Hint, _Sort

Check warning on line 18 in cratedb_toolkit/adapter/pymongo/cursor.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/adapter/pymongo/cursor.py#L17-L18

Added lines #L17 - L18 were not covered by tests
from pymongo.errors import InvalidOperation
from pymongo.message import _GetMore, _Query
from pymongo.read_preferences import _ServerMode
Expand Down Expand Up @@ -119,7 +120,7 @@
allow_disk_use = validate_boolean("allow_disk_use", allow_disk_use)

if projection is not None:
projection = helpers._fields_list_to_dict(projection, "projection")
projection = helpers_shared._fields_list_to_dict(projection, "projection")

Check warning on line 123 in cratedb_toolkit/adapter/pymongo/cursor.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/adapter/pymongo/cursor.py#L123

Added line #L123 was not covered by tests

if let is not None:
validate_is_document_type("let", let)
Expand All @@ -131,7 +132,7 @@
self.__skip = skip
self.__limit = limit
self.__batch_size = batch_size
self.__ordering = sort and helpers._index_document(sort) or None
self.__ordering = sort and helpers_shared._index_document(sort) or None

Check warning on line 135 in cratedb_toolkit/adapter/pymongo/cursor.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/adapter/pymongo/cursor.py#L135

Added line #L135 was not covered by tests
self.__max_scan = max_scan
self.__explain = False
self.__comment = comment
Expand Down Expand Up @@ -287,8 +288,8 @@

def sort(self, key_or_list: _Hint, direction: Optional[Union[int, str]] = None) -> Cursor[_DocumentType]:
""" """
keys = helpers._index_list(key_or_list, direction)
self.__ordering = helpers._index_document(keys)
keys = helpers_shared._index_list(key_or_list, direction)
self.__ordering = helpers_shared._index_document(keys)

Check warning on line 292 in cratedb_toolkit/adapter/pymongo/cursor.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/adapter/pymongo/cursor.py#L291-L292

Added lines #L291 - L292 were not covered by tests
return self

def __send_message(self, operation: Union[_Query, _GetMore]) -> None:
Expand Down Expand Up @@ -385,6 +386,6 @@
if isinstance(index, str):
self.__hint = index
else:
self.__hint = SON(helpers._index_document(index))
self.__hint = SON(helpers_shared._index_document(index))

Check warning on line 389 in cratedb_toolkit/adapter/pymongo/cursor.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/adapter/pymongo/cursor.py#L389

Added line #L389 was not covered by tests

return AmendedCursor
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mongodb = [
pymongo = [
"jessiql==1.0.0rc1",
"pandas==2.1.*",
"pymongo<4.9",
"pymongo<4.10,>=4.9.1",
"sqlalchemy<2",
]
release = [
Expand Down
Loading