Skip to content

Commit 88434b6

Browse files
Kn99HNShaneHarvey
authored andcommitted
PYTHON-1880: Raise a warning when no_cursor_timeout is used with an implicit session (#594)
(cherry picked from commit 1818553)
1 parent 937e16d commit 88434b6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pymongo/cursor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ def __init__(self, collection, filter=None, projection=None, skip=0,
147147
if not isinstance(limit, int):
148148
raise TypeError("limit must be an instance of int")
149149
validate_boolean("no_cursor_timeout", no_cursor_timeout)
150+
if no_cursor_timeout and not self.__explicit_session:
151+
warnings.warn("use an explicit session with no_cursor_timeout=True "
152+
"otherwise the cursor may still timeout after "
153+
"30 minutes, for more info see "
154+
"https://docs.mongodb.com/v4.4/reference/method/"
155+
"cursor.noCursorTimeout/"
156+
"#session-idle-timeout-overrides-nocursortimeout",
157+
UserWarning, stacklevel=2)
150158
if cursor_type not in (CursorType.NON_TAILABLE, CursorType.TAILABLE,
151159
CursorType.TAILABLE_AWAIT, CursorType.EXHAUST):
152160
raise ValueError("not a valid value for cursor_type")

0 commit comments

Comments
 (0)