File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -291,7 +291,12 @@ def _clone_base(self, session):
291
291
def __die (self , synchronous = False ):
292
292
"""Closes this cursor.
293
293
"""
294
- already_killed = self .__killed
294
+ try :
295
+ already_killed = self .__killed
296
+ except AttributeError :
297
+ # __init__ did not run to completion (or at all).
298
+ return
299
+
295
300
self .__killed = True
296
301
if self .__id and not already_killed :
297
302
if self .__exhaust and self .__exhaust_mgr :
Original file line number Diff line number Diff line change 35
35
ALL ,
36
36
OFF )
37
37
from pymongo .collation import Collation
38
- from pymongo .cursor import CursorType
38
+ from pymongo .cursor import Cursor , CursorType
39
39
from pymongo .errors import (ConfigurationError ,
40
40
ExecutionTimeout ,
41
41
InvalidOperation ,
@@ -1409,6 +1409,12 @@ def assertCursorKilled():
1409
1409
else :
1410
1410
self .assertEqual (0 , len (results ["started" ]))
1411
1411
1412
+ def test_delete_not_initialized (self ):
1413
+ # Creating a cursor with invalid arguments will not run __init__
1414
+ # but will still call __del__, eg test.find(invalidKwarg=1).
1415
+ cursor = Cursor .__new__ (Cursor ) # Skip calling __init__
1416
+ cursor .__del__ () # no error
1417
+
1412
1418
1413
1419
class TestRawBatchCursor (IntegrationTest ):
1414
1420
def test_find_raw (self ):
You can’t perform that action at this time.
0 commit comments