New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support generators as return values to __getitem__
on mongomock.collection.Cursor
#130
Comments
Are you planning to create a PR ? |
I have the issue too with lists. @akellehe fix to return an iterator works for me. I can do a PR, but I'm really not sure what other effects it would have. that said, running |
I'll submit a PR this evening. |
I'm running with an issue with a complicated prepared queryset, with the
I didn't identify why or how to reproduce simply, but returning a cursor (which has clone) fixes the problem in my case : |
Could @abondis' commit (2759170) be cherry picked into mongomock? I'm running into this issue, and it seems like the fix has been found, but not yet included. (For those using |
I think that @touilleMan did it in d7aeac1, thanks Emmanuel. please reopen if I'm wrong. |
If a call to
mongomock.collection.Cursor.__getitem__
expects amongomock.collection.Cursor
and gets alist
(for example inmongoengine
's slicing methodsModel.objects.all()[start:finish]
) we get an exception thatlist
has no attribute/methodnext
. The fix is super-easy, you just have to check herehttps://github.com/vmalloc/mongomock/blob/master/mongomock/collection.py#L876
to see if the return value would be an instance of
list
:There are a few other methods in the
Cursor
class that could use a little refactoring.distinct
, for example, might be better as (for the same reason):The text was updated successfully, but these errors were encountered: