json.dumps因使用ORDER BY而不是其他人的GqlQuery的某些结果而失败

时间:2013-03-25 06:20:43

标签: json google-app-engine python-2.7 gqlquery

这个问题很难解释。我差不多完成了这个大规模的学校项目,但最后一个问题就是这个奇怪的错误。我正在使用Python API for Google App Engine。我的模型包括:

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()])

标准,简单的东西。但是,这很好用:

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

但即使没有消息,这个几乎相同的类也会抛出500:

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

两者之间的唯一区别是一个是搜索消息而另一个是旅行。如果我将GqlQuery更改为(“SELECT * FROM Message WHERE ANCESTOR IS:1”,Team.get_by_id(long(team_id))那么它工作正常。但是当ORDER BY在那里时,它会在它转到json时中断.dumps。我的斗智结束了......现在有这个问题了一天。任何想法都会非常感激。

编辑:这是相关的index.yaml代码:

indexes:

- kind: Message
   ancestor: yes
   properties:
   - name: date
     direction: desc

# AUTOGENERATED

这是数据存储索引页面的屏幕截图,显示索引正在服务: http://i.imgur.com/DXhK9vy.png

0 个答案:

没有答案