google-app-enginegoogle-cloud-datastoreapp-engine-ndbendpoints-proto-datastore

EndpointsAliasProperty filtering error


I am trying to implement custom query responses using EndpointsAliasProperty. Here is the code

self._endpoints_query_info._filters.add(MyModel.hash_tag.IN(['a', 'b', 'c']))

It is giving me an error

BadArgumentError: _MultiQuery with cursors requires __key__ order

how can I solve this? Is there a way to implement above idea?


Solution

  • Related question about the general problem here: BadArgumentError: _MultiQuery with cursors requires __key__ order in ndb

    To accomplish the necessary ordering with endpoints the easiest way is to explicitely add it to your query method:

    @MyModel.query_method(...)
    def mymodel_list(self, query):
    
        ...
        query = query.order(MyModel._key)
        return query