我遇到了一个问题,可能是因为我不了解GQL是如何工作的(这是我第一天用它)。我正在使用google.appengine.ext.db数据存储处理Google AppEngine(现在在本地)。
我只是创建一个具有特定ID的用户,然后尝试通过过滤来检索它,以包含仅包含此ID的记录。当我尝试这个时,它什么都不返回,但当我得到所有,迭代并逐个比较ID时,它会找到记录。我肯定没有看到一些愚蠢的错误。这是代码:
def datastore_key():
return db.Key.from_path('MyUsers', 'all')
class MyUser(db.Model):
my_id = db.TextProperty()
[...]
user = MyUser(parent=datastore_key())
user.my_id = "7wjew1"
user.put()
users = MyUser.all()
users.ancestor(datastore_key())
users.filter("my_id = ", "7wjew1") # WTF - why isn't this working???
print users[0] # is None, users list is empty
# now, let's get all users
users = MyUser.all()
users.ancestor(datastore_key())
# and iterate through the list to check for ids
for user in users:
if user.linkedin_id == user_id:
print "ids are the same"
# surprise, it prints the "ids are the same" - wtf?
答案 0 :(得分:1)
好吧我想有时候写一个问题会让你自己想出答案。我将TextProperty
更改为StringProperty
并且有效:)