diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 66533c13d..d75bdb1a0 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -21,6 +21,7 @@ env: PYMONGO_3_9: 3.9 PYMONGO_3_11: 3.11 PYMONGO_3_12: 3.12 + PYMONGO_4_0: 4.0 MAIN_PYTHON_VERSION: 3.7 @@ -61,6 +62,9 @@ jobs: - python-version: 3.7 MONGODB: $MONGODB_4_4 PYMONGO: $PYMONGO_3_12 + - python-version: 3.9 + MONGODB: $MONGODB_4_4 + PYMONGO: $PYMONGO_4_0 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/mongoengine/context_managers.py b/mongoengine/context_managers.py index 0ca2622c5..eb9c99622 100644 --- a/mongoengine/context_managers.py +++ b/mongoengine/context_managers.py @@ -210,13 +210,14 @@ def __init__(self, alias=DEFAULT_CONNECTION_NAME): } def _turn_on_profiling(self): - self.initial_profiling_level = self.db.profiling_level() - self.db.set_profiling_level(0) + profile_update_res = self.db.command({"profile": 0}) + self.initial_profiling_level = profile_update_res["was"] + self.db.system.profile.drop() - self.db.set_profiling_level(2) + self.db.command({"profile": 2}) def _resets_profiling(self): - self.db.set_profiling_level(self.initial_profiling_level) + self.db.command({"profile": self.initial_profiling_level}) def __enter__(self): self._turn_on_profiling() diff --git a/mongoengine/document.py b/mongoengine/document.py index e56a9e7c2..5d6a47a0e 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -888,10 +888,6 @@ def ensure_indexes(cls): index_cls = cls._meta.get("index_cls", True) collection = cls._get_collection() - # 746: when connection is via mongos, the read preference is not necessarily an indication that - # this code runs on a secondary - if not collection.is_mongos and collection.read_preference > 1: - return # determine if an index which we are creating includes # _cls as its first field; if so, we can avoid creating diff --git a/setup.py b/setup.py index bb777da0e..78e20331b 100644 --- a/setup.py +++ b/setup.py @@ -142,7 +142,7 @@ def run_tests(self): platforms=["any"], classifiers=CLASSIFIERS, python_requires=">=3.6", - install_requires=["pymongo>=3.4, <4.0"], + install_requires=["pymongo>=3.4,<=4.0"], cmdclass={"test": PyTest}, **extra_opts ) diff --git a/tests/test_context_managers.py b/tests/test_context_managers.py index 4ea7fa5ab..68dc8f4be 100644 --- a/tests/test_context_managers.py +++ b/tests/test_context_managers.py @@ -269,17 +269,23 @@ def test_query_counter_temporarily_modifies_profiling_level(self): connect("mongoenginetest") db = get_db() - initial_profiling_level = db.profiling_level() + def _current_profiling_level(): + return db.command({"profile": -1})["was"] + + def _set_profiling_level(lvl): + db.command({"profile": lvl}) + + initial_profiling_level = _current_profiling_level() try: new_level = 1 - db.set_profiling_level(new_level) - assert db.profiling_level() == new_level + _set_profiling_level(new_level) + assert _current_profiling_level() == new_level with query_counter(): - assert db.profiling_level() == 2 - assert db.profiling_level() == new_level + assert _current_profiling_level() == 2 + assert _current_profiling_level() == new_level except Exception: - db.set_profiling_level( + _set_profiling_level( initial_profiling_level ) # Ensures it gets reseted no matter the outcome of the test raise diff --git a/tox.ini b/tox.ini index 9925787b2..98c367b44 100644 --- a/tox.ini +++ b/tox.ini @@ -10,5 +10,6 @@ deps = mg39: pymongo>=3.9,<3.10 mg311: pymongo>=3.11,<3.12 mg312: pymongo>=3.12,<3.13 + mg4: pymongo>=4.0,<4.1 setenv = PYTHON_EGG_CACHE = {envdir}/python-eggs