Note that there are some explanatory texts on larger screens.

plurals
  1. POjson.dumps fails for some results of GqlQuery with ORDER BY and not others
    text
    copied!<p>This problem is hard to explain. I'm almost done with this massive project for school, but the last sticking point is this bizarre error. I'm using the Python API for Google App Engine. My models include these:</p> <pre><code>class Message(db.Model): date = db.DateTimeProperty(auto_now_add=True) content = db.StringProperty(multiline=True) author = db.StringProperty() recipients = db.StringListProperty() theTeam = db.StringProperty() theTrip = db.StringProperty() messageType = db.IntegerProperty() def to_dict(self): return dict([(p, unicode(getattr(self, p))) for p in self.properties()]) class Trip(db.Model): name = db.StringProperty() members = db.StringListProperty() date = db.DateTimeProperty(auto_now_add=True) def to_dict(self): return dict([(p, unicode(getattr(self, p))) for p in self.properties()]) </code></pre> <p>Just standard, simple stuff. However, this works fine:</p> <pre><code>class GetTeamTrips(webapp2.RequestHandler): def post(self): team_id = self.request.get('team_id') trips = db.GqlQuery("SELECT * FROM Trip WHERE ANCESTOR IS :1 ORDER BY date DESC LIMIT 20", Team.get_by_id(long(team_id))) self.response.out.write(json.dumps([trip.to_dict() for trip in trips])) </code></pre> <p>But this nearly identical class throws a 500 even when there are no Messages:</p> <pre><code>class GetTeamMessages(webapp2.RequestHandler): def post(self): team_id=self.request.get('team_id') messages = db.GqlQuery("SELECT * FROM Message WHERE ANCESTOR IS :1 ORDER BY date DESC LIMIT 20", Team.get_by_id(long(team_id))) self.response.out.write(json.dumps([message.to_dict() for message in messages])) </code></pre> <p>The only difference between the two is that one is searching messages and the other trips. If I change the GqlQuery to be ("SELECT * FROM Message WHERE ANCESTOR IS :1", Team.get_by_id(long(team_id)) then it works fine. But with the ORDER BY in there, it breaks when it goes to the json.dumps. I'm at my wits end with this...had this problem for a day now. Any thoughts would be greatly appreciated.</p> <p>EDIT: Here is the relevant index.yaml code:</p> <pre><code>indexes: - kind: Message ancestor: yes properties: - name: date direction: desc # AUTOGENERATED </code></pre> <p>And here is a screenshot of the Datastore Indexes page, showing that the index is serving: <a href="http://i.imgur.com/DXhK9vy.png" rel="nofollow">http://i.imgur.com/DXhK9vy.png</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload