diff --git a/cratedb_toolkit/adapter/pymongo/api.py b/cratedb_toolkit/adapter/pymongo/api.py index ab17726d..826ba7e1 100644 --- a/cratedb_toolkit/adapter/pymongo/api.py +++ b/cratedb_toolkit/adapter/pymongo/api.py @@ -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): diff --git a/cratedb_toolkit/adapter/pymongo/cursor.py b/cratedb_toolkit/adapter/pymongo/cursor.py index 04c5825a..09a79a72 100644 --- a/cratedb_toolkit/adapter/pymongo/cursor.py +++ b/cratedb_toolkit/adapter/pymongo/cursor.py @@ -11,12 +11,13 @@ import sqlalchemy as sa from bson import SON -from pymongo import CursorType, helpers +from pymongo import CursorType, helpers_shared 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 from pymongo.errors import InvalidOperation from pymongo.message import _GetMore, _Query from pymongo.read_preferences import _ServerMode @@ -121,7 +122,7 @@ def __init__( 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") if let is not None: validate_is_document_type("let", let) @@ -133,7 +134,7 @@ def __init__( 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 self.__max_scan = max_scan self.__explain = False self.__comment = comment @@ -289,8 +290,8 @@ def _refresh(self) -> int: 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) return self def __send_message(self, operation: Union[_Query, _GetMore]) -> None: @@ -387,6 +388,6 @@ def __set_hint(self, index: Optional[_Hint]) -> None: if isinstance(index, str): self.__hint = index else: - self.__hint = SON(helpers._index_document(index)) + self.__hint = SON(helpers_shared._index_document(index)) return AmendedCursor diff --git a/pyproject.toml b/pyproject.toml index 8bff9c00..47b8898c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -227,7 +227,7 @@ optional-dependencies.pymongo = [ "jessiql==1.0.0rc1", "numpy<2", "pandas<2.2", - "pymongo<4.9", + "pymongo>=4.9.1,<4.10", "setuptools<81", "sqlalchemy<2", ] diff --git a/tests/adapter/test_pymongo.py b/tests/adapter/test_pymongo.py index aed2acec..854485bf 100644 --- a/tests/adapter/test_pymongo.py +++ b/tests/adapter/test_pymongo.py @@ -4,7 +4,6 @@ from unittest import mock import pytest -from verlib2 import Version pymongo = pytest.importorskip("pymongo", reason="Skipping tests because pymongo is not installed") @@ -13,9 +12,6 @@ check_sqlalchemy1(allow_module_level=True) -if Version(pymongo.version) >= Version("4.9"): - raise pytest.skip("This feature or subsystem needs PyMongo 4.8", allow_module_level=True) - from cratedb_toolkit.adapter.pymongo import PyMongoCrateDBAdapter from cratedb_toolkit.adapter.pymongo.util import AmendedObjectId from cratedb_toolkit.util.date import truncate_milliseconds