0

Error returned is 500 Internal server error when the running app processes a get request for ViewDogs. At GAE Stack Driver console I get:

NeedIndexError: no matching index found - recommended index is: 
- kind:Dog 
  ancestor: yes 
  properties: - 
     name: id 
     direction: desc".

I confirm there is an index loaded named Dog and it currently shows "Serving"

Also confirm there are 4 dogs created successfully, and they can be queried from the DataStore Entities tab individually and with SELECT * FROM Dog. Also note the commented out line self.response.write('You dog!') which returns as expected when uncommented, so presumably not a route issue. I can return a single dog via GET (this code omitted) Code within class ViewAllDogs is likely faulty, did my best with the GAE docs.

index.yaml file, which I confirm is uploaded and has status: "serving"

indexes:
- kind: Dog
  ancestor: yes
  properties:- name: id
    direction: desc
  - name: name
    direction: desc
  - name: type
    direction: desc
  - name: weight
    direction: desc
  - name: boarded
    direction: desc

app.yaml file:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: main.app

main.py

import webapp2
from datetime import datetime
from google.appengine.ext import ndb
import webbrowser
import json

def gql_json_parser(query_obj):
    result = []
    for entry in query_obj:
        result.append(dict([(p, unicode(getattr(entry, p))) for p in entry.properties()]))
    return result

class Dog(ndb.Model):
    """ Models an individual Dog """
    id = ndb.StringProperty(required = True, indexed = True)
    name = ndb.StringProperty(required = True, indexed = True)
    type = ndb.StringProperty(required = True, indexed = True)
    weight = ndb.IntegerProperty(required = True, indexed = True)
    boarded = ndb.BooleanProperty(required = True, indexed = True)

    @classmethod
    def query_dog(cls, ancestor_key):
        return cls.query(ancestor=ancestor_key).order(-cls.id)

class ViewAllDogs(webapp2.RequestHandler):
    def get(self):
#       self.response.write('You dog!')
        parent_dog = self.request.get('parent_dog')
        ancestor_key = ndb.Key("Dog", parent_dog or '*noDogs*')
        query_data = Dog.query_dog(ancestor_key).fetch(10)
        json_query_data = gql_json_parser(query_data)
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(json_query_data))

app = webapp2.WSGIApplication([
    ('/ViewDogs', ViewAllDogs)
], debug=True)

Similar questions abound, inlcuding this Query google app engine datastore for all entities but none are solving my issue. Thanks.

Community
  • 1
  • 1
RigidBody
  • 656
  • 3
  • 11
  • 26
  • 1
    Notice the index missing is different to the index you have defined. The index you need must exactly what is required. – Tim Hoffman Apr 22 '17 at 07:04
  • Have you tried it again a few minutes later? When you make changes to your queries or data structure, Datastore indexes take a few minutes to update after you deploy (maybe several, depending on the size of your data). In a production environment, you may want to use the `--no-promote` flag, wait for the indexes to update and then directing traffic to the new version deployed. – Renato Byrro Apr 24 '17 at 12:04

1 Answers1

0

As usual, I was making it much more complicated than need be...

import webapp2, json
from datetime import datetime
from google.appengine.ext import ndb

MAXDOGS = 100

class Dog(ndb.Model):
    """ Models an individual Dog """
    id = ndb.StringProperty(required = True, indexed = True)
    name = ndb.StringProperty(required = True, indexed = True)
    type = ndb.StringProperty(required = True, indexed = True)
    weight = ndb.IntegerProperty(required = True, indexed = True)
    boarded = ndb.BooleanProperty(required = True, indexed = True)

class ViewAllDogs(webapp2.RequestHandler):
    def get(self):
        query_data = Dog.query()
        results = query.fetch(limit = MAX_SLIPS)
        aList = []
        for match in results:
            aList.append({'id': match.id, 'name': match.name, 'type': match.type, 
                          'weight': match.weight, 'boarded': match.boarded})
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(aList))

app = webapp2.WSGIApplication([
    ('/ViewDogs', ViewAllDogs)
RigidBody
  • 656
  • 3
  • 11
  • 26