Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BadArgumentError: _MultiQuery with cursors requires __key__ order in ndb

I can't understand what this error means and apparently, no one ever got the same error on the internet

BadArgumentError: _MultiQuery with cursors requires __key__ order

This happens here:

return SocialNotification.query().order(-SocialNotification.date).filter(SocialNotification.source_key.IN(nodes_list)).fetch_page(10)

The property source_key is obviously a key and nodes_list is a list of entity keys previously retrieved.

What I need is to find all the SocialNotifications that have a field source_key that match one of the keys in the list.

like image 725
Chobeat Avatar asked Sep 16 '12 17:09

Chobeat


1 Answers

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).

like image 67
Guido van Rossum Avatar answered Oct 04 '22 23:10

Guido van Rossum