-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 0.4
-
Component/s: None
-
None
The following is not the right way to iterate a MotorCursor:
for doc in cursor:
pass
Motor should throw TypeError: MotorCursor object is not iterable. Instead, "doc" is bound to the cursor itself and the loop runs forever.
This is because, to my surprise, a Python object without an __iter__ is still iterable if it implements __getitem__. The for-loop first calls:
MotorCursor.__getitem__(0)
...which updates the delegate Cursor's skip and limit and returns the original MotorCursor. Hence the infinite loop.
It's probably best to delete __getitem__ and require you to use skip() and limit() instead; implementing __getitem__ falsely implies that a MotorCursor is iterable by conventional methods.
- depends on
-
MOTOR-84 Drop support for indexing Motor cursors with "[n]"
- Closed