GQL の仕組みを理解していないことが原因であると思われる問題があります (これは GQL を初めて使用した日です)。私は google.appengine.ext.db データ ストレージを使用して Google AppEngine (ローカルで現在) に取り組んでいます。
特定のIDを持つユーザーを作成し、フィルタリングしてこのIDのみのレコードを含めるように取得しようとしています。これを試してみると何も返されませんが、すべてを取得して ID を 1 つずつ繰り返して比較すると、レコードが見つかります。ここには確かに、私が見ていないばかげたエラーがあります。コードは次のとおりです。
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?