Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDB map(callback, produces_cursors=True)

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)
like image 932
Chris Avatar asked Oct 06 '22 11:10

Chris


1 Answers

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.

like image 171
Guido van Rossum Avatar answered Oct 10 '22 11:10

Guido van Rossum