Skip to content

Commit 8dc0fcc

Browse files
committed
MongoDB: Update adapter to pymongo 4.9
pymongo 4.9 has been released, and includes a few breaking API changes after adding an asynchronous variant to the driver.
1 parent 5c031f0 commit 8dc0fcc

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

cratedb_toolkit/adapter/pymongo/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def __init__(self, dburi: str):
2323
patch("pymongo.collection.Collection", collection_patched),
2424
patch("pymongo.database.Collection", collection_patched),
2525
# Converge a few low-level functions of PyMongo to no-ops.
26-
patch("pymongo.mongo_client.MongoClient._ensure_session"),
27-
patch("pymongo.mongo_client._ClientConnectionRetryable._get_server"),
26+
patch("pymongo.synchronous.mongo_client.MongoClient._ensure_session"),
27+
patch("pymongo.synchronous.mongo_client._ClientConnectionRetryable._get_server"),
2828
]
2929

3030
def start(self):

cratedb_toolkit/adapter/pymongo/cursor.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
import sqlalchemy as sa
1313
from bson import SON
14-
from pymongo import CursorType, helpers
14+
from pymongo import CursorType, helpers_shared
1515
from pymongo.client_session import ClientSession
1616
from pymongo.collation import validate_collation_or_none
1717
from pymongo.collection import Collection
1818
from pymongo.common import validate_is_document_type, validate_is_mapping
19-
from pymongo.cursor import _QUERY_OPTIONS, Cursor, _Hint, _Sort
19+
from pymongo.cursor import Cursor
20+
from pymongo.cursor_shared import _QUERY_OPTIONS, _Hint, _Sort
2021
from pymongo.errors import InvalidOperation
2122
from pymongo.message import _GetMore, _Query
2223
from pymongo.read_preferences import _ServerMode
@@ -121,7 +122,7 @@ def __init__(
121122
allow_disk_use = validate_boolean("allow_disk_use", allow_disk_use)
122123

123124
if projection is not None:
124-
projection = helpers._fields_list_to_dict(projection, "projection")
125+
projection = helpers_shared._fields_list_to_dict(projection, "projection")
125126

126127
if let is not None:
127128
validate_is_document_type("let", let)
@@ -133,7 +134,7 @@ def __init__(
133134
self.__skip = skip
134135
self.__limit = limit
135136
self.__batch_size = batch_size
136-
self.__ordering = sort and helpers._index_document(sort) or None
137+
self.__ordering = sort and helpers_shared._index_document(sort) or None
137138
self.__max_scan = max_scan
138139
self.__explain = False
139140
self.__comment = comment
@@ -289,8 +290,8 @@ def _refresh(self) -> int:
289290

290291
def sort(self, key_or_list: _Hint, direction: Optional[Union[int, str]] = None) -> Cursor[_DocumentType]:
291292
""" """
292-
keys = helpers._index_list(key_or_list, direction)
293-
self.__ordering = helpers._index_document(keys)
293+
keys = helpers_shared._index_list(key_or_list, direction)
294+
self.__ordering = helpers_shared._index_document(keys)
294295
return self
295296

296297
def __send_message(self, operation: Union[_Query, _GetMore]) -> None:
@@ -387,6 +388,6 @@ def __set_hint(self, index: Optional[_Hint]) -> None:
387388
if isinstance(index, str):
388389
self.__hint = index
389390
else:
390-
self.__hint = SON(helpers._index_document(index))
391+
self.__hint = SON(helpers_shared._index_document(index))
391392

392393
return AmendedCursor

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ optional-dependencies.pymongo = [
227227
"jessiql==1.0.0rc1",
228228
"numpy<2",
229229
"pandas<2.2",
230-
"pymongo<4.9",
230+
"pymongo>=4.9.1,<4.10",
231231
"setuptools<81",
232232
"sqlalchemy<2",
233233
]

0 commit comments

Comments
 (0)