Skip to content
Closed
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: 4 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}
Expand Down
9 changes: 5 additions & 4 deletions mongoengine/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions mongoengine/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
18 changes: 12 additions & 6 deletions tests/test_context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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