5
votes

The Google AppEngine NDB Documentation for map() states that:

"All query options keyword arguments are supported."

However, I have tried to use produces_cursors=True on map() and I'm not getting a cursor back.

map(callback, pass_batch_into_callback=None, merge_future=None, **q_options)

I'd like to use map() as I can set the callback to a tasklet.

https://developers.google.com/appengine/docs/python/ndb/queryclass#kwdargs_options

Edit - Providing code sample:

@ndb.tasklet
def callback(user):
    statistics = yield ndb.Key(Statistics, user.key.id()).get_async()
    raise ndb.Return(user, statistics)

result = User.query().map(callback, produces_cursors=True)
1
Can you provide a code snippet? - bossylobster
Sure @bossylobster , I've added some sample code. - Chris
Indeed you are correct, tasklets.MultiFuture only returns a list (code.google.com/p/appengine-ndb-experiment/source/browse/ndb/…) and map_query doesn't keep any of the cursor information around. - bossylobster
Hi @Chris it appears to me that you managed to get the cursors somehow working, in my case even without having typos something is going wrong. I have described it elaboratly here, stackoverflow.com/questions/21118732/… May be you can spot something obvious that's getting overlooked by me. Appreciate your help. - Harshal Patil
@HarshalPatil - Guido mentions below that map() doesn't return cursors, does that help? - Chris

1 Answers

4
votes

The example seems to have a typo -- the correct flag is produce_cursors, not produces_cursors.

But cursors are only made available when you use an iterator, not with map(). Check out the async iterators example; it's a little bit of work but you can definitely use it to manually create a tasklet for each result.