My code is intended to:
- Retrieve a user_id from a cookie, if it exists.
- Query the datastore using the user_id to retrieve the user record.
- Finally, if a record is found, it displays a welcome message. (signup is passed to a template)
I cannot get the app to display the welcome message. As far as I can tell the issue is that the query always returns None. I've verified the cookie and the data in the datastore exists.
What am I doing wrong with this query? Does GQL handle IDs in where clauses in a non-intuitive way?
#Get cookie
user_id = self.request.cookies.get("user_id", 0)
#Query Datastore for matching user_id
user = db.GqlQuery("SELECT * FROM User WHERE id = %s" % user_id).get()
#If a user is found, display the username
if user.username:
signup = "Welcome, %s" % user.username