From d6fa19605bb54d9eac4d6d35afb87e1734fe3d11 Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Mon, 19 Apr 2021 21:14:02 -0400 Subject: [PATCH 1/2] Add userwarning to no_cursor_timeout --- pymongo/cursor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pymongo/cursor.py b/pymongo/cursor.py index b051b068af..6048f1620c 100644 --- a/pymongo/cursor.py +++ b/pymongo/cursor.py @@ -144,6 +144,11 @@ def __init__(self, collection, filter=None, projection=None, skip=0, if not isinstance(limit, int): raise TypeError("limit must be an instance of int") validate_boolean("no_cursor_timeout", no_cursor_timeout) + if no_cursor_timeout: + warnings.warn("use an explicit session with no_cursor_timeout=True"\ + "otherwise the cursor may still timeout after 30 minutes,"\ + "for more info see DOCS-11255", + UserWarning, stacklevel=2) if cursor_type not in (CursorType.NON_TAILABLE, CursorType.TAILABLE, CursorType.TAILABLE_AWAIT, CursorType.EXHAUST): raise ValueError("not a valid value for cursor_type") From 5cd20cc9dd438b0b9536c89646c515484e6226ac Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Thu, 22 Apr 2021 13:13:15 -0400 Subject: [PATCH 2/2] Check for __explicit_session and reformat warning message --- pymongo/cursor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pymongo/cursor.py b/pymongo/cursor.py index 6048f1620c..9d39de544b 100644 --- a/pymongo/cursor.py +++ b/pymongo/cursor.py @@ -144,10 +144,13 @@ def __init__(self, collection, filter=None, projection=None, skip=0, if not isinstance(limit, int): raise TypeError("limit must be an instance of int") validate_boolean("no_cursor_timeout", no_cursor_timeout) - if no_cursor_timeout: - warnings.warn("use an explicit session with no_cursor_timeout=True"\ - "otherwise the cursor may still timeout after 30 minutes,"\ - "for more info see DOCS-11255", + if no_cursor_timeout and not self.__explicit_session: + warnings.warn("use an explicit session with no_cursor_timeout=True " + "otherwise the cursor may still timeout after " + "30 minutes, for more info see " + "https://docs.mongodb.com/v4.4/reference/method/" + "cursor.noCursorTimeout/" + "#session-idle-timeout-overrides-nocursortimeout", UserWarning, stacklevel=2) if cursor_type not in (CursorType.NON_TAILABLE, CursorType.TAILABLE, CursorType.TAILABLE_AWAIT, CursorType.EXHAUST):