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):
291291 def __die (self , synchronous = False ):
292292 """Closes this cursor.
293293 """
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+
295300 self .__killed = True
296301 if self .__id and not already_killed :
297302 if self .__exhaust and self .__exhaust_mgr :
Original file line number Diff line number Diff line change 3535 ALL ,
3636 OFF )
3737from pymongo .collation import Collation
38- from pymongo .cursor import CursorType
38+ from pymongo .cursor import Cursor , CursorType
3939from pymongo .errors import (ConfigurationError ,
4040 ExecutionTimeout ,
4141 InvalidOperation ,
@@ -1409,6 +1409,12 @@ def assertCursorKilled():
14091409 else :
14101410 self .assertEqual (0 , len (results ["started" ]))
14111411
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+
14121418
14131419class TestRawBatchCursor (IntegrationTest ):
14141420 def test_find_raw (self ):
You can’t perform that action at this time.
0 commit comments