Skip to content

Commit 0c58a62

Browse files
committed
coundt_docs: Only pass session kwarg to methods that expect it
1 parent afcd26e commit 0c58a62

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mongoengine/pymongo_support.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ def count_documents(
3636
kwargs["hint"] = hint
3737
if collation is not None:
3838
kwargs["collation"] = collation
39-
kwargs["session"] = connection._get_session()
4039

4140
# count_documents appeared in pymongo 3.7
4241
if PYMONGO_VERSION >= (3, 7):
4342
try:
4443
if not filter and set(kwargs) <= {"max_time_ms"}:
4544
# when no filter is provided, estimated_document_count
4645
# is a lot faster as it uses the collection metadata
47-
return collection.estimated_document_count(**kwargs)
46+
return collection.estimated_document_count(
47+
session=connection._get_session(), **kwargs
48+
)
4849
else:
49-
return collection.count_documents(filter=filter, **kwargs)
50+
return collection.count_documents(
51+
filter=filter, session=connection._get_session(), **kwargs
52+
)
5053
except OperationFailure as err:
5154
if PYMONGO_VERSION >= (4,):
5255
raise

0 commit comments

Comments
 (0)