michuk
michuk

Reputation: 1432

Simple data storing / retrieving in GQL on Google AppEngine in Python

I have a problem which probably is a result of me not understanding how GQL works (this is my first day with it). I'm working on Google AppEngine (locally now) using google.appengine.ext.db data storage.

I'm simply creating a user with certain ID and then trying to retrieve it by filtering to include records with this ID only. When I try this, it returns nothing, but when I get all, iterate and compare the IDs one by one, it finds the record. There is certainly some stupid error here I'm not seeing. Here is the code:

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?

Upvotes: 0

Views: 143

Answers (1)

michuk
michuk

Reputation: 1432

OK I guess it's sometimes good to write a question so that you come up with an answer yourself right away. I changed TextProperty to StringProperty and it worked :)

Upvotes: 1

Related Questions