BadArgumentError: _MultiQuery with cursors requires __key__ order in ndb

后端 未结 5 2038
终归单人心
终归单人心 2021-01-18 01:27

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

相关标签:
5条回答
  • 2021-01-18 02:09

    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.

    0 讨论(0)
  • 2021-01-18 02:12

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

    0 讨论(0)
  • 2021-01-18 02:13

    You need to the property you want to order on and key.

    .order(-SocialNotification.date, SocialNotification.key)
    
    0 讨论(0)
  • 2021-01-18 02:21

    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.

    0 讨论(0)
  • 2021-01-18 02:26

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

    0 讨论(0)
提交回复
热议问题