I can\'t understand what this error means and apparently, no one ever got the same error on the internet
BadArgumentError: _MultiQuery with cursors re
I had the same error when filtering without a group. The error occurred every time my filter returned more than one result.
To fix it I actually had to add ordering by key.
It seems that this also happens when you filter for an inequality and try to fetch a page.
(e.g. MyModel.query(MyModel.prop != 'value').fetch_page(...)
. This basically means (unless i missed something) that you can't fetch_page when using an inequality filter because on one hand you need the sort to be MyModel.prop
but on the other hand you need it to be MyModel._key
, which is hard :)
You need to the property you want to order on and key.
.order(-SocialNotification.date, SocialNotification.key)
I found the answer here: https://developers.google.com/appengine/docs/python/ndb/queries#cursors
You can change your query to:
SocialNotification.query().order(-SocialNotification.date, SocialNotification.key).filter(SocialNotification.source_key.IN(nodes_list)).fetch_page(10)
in order to get this to work. Note that it seems to be slow (18 seconds) when nodes_list is large (1000 entities), at least on the Development server. I don't have a large amount of test data on a test server.
The error message tries to tell you you that queries involving IN and cursors must be ordered by __key__
(which is the internal name for the key of the entity). (This is needed so that the results can be properly merged and made unique.) In this case you have to replace your .order()
call with .order(SocialNotification._key)
.