Reputation: 3113
Update: The only answer yet given is not helping me. The code works as desired on my local system but does not work in the deployed Python app. This is a series problem for me. Please give this question a serious second look.
Here is some simplified code to show what is happening. When the simplified code is put into the interactive console for the SDK, it always prints out Hello, schott.brian
, but in the deployed app its like it prints out no match
. What's up with that?
user = "schott.brian"
name = "schott.brian"
if user and user == name:
print "Hello, " + user
else:
print "no match"
Here is my code. Notice the second if
checks if user and (user == person.user):
user = users.get_current_user()
ID_id = self.request.get("ID", None)
ID_id = ''.join(ID_id.split())
key = db.Key.from_path("PQ", ID_id)
person = PQ.get(key)
if person: #person's ID DOES exist already
logging.info("6 person %s" % person.user )
logging.info("6 key %s" % key )
logging.info("6 ID_id %s" % ID_id )
logging.info("6 user %s" % user )
if user and (user == person.user):
# never get here on gae, but works on sdk
else:
# always gets to here by mistake on gae, but works on SDKs
logging.info("7 user %s" % user )
logging.info("7 person %s" % person.user )
Here are the logs for that code on gae and even though user exists and (user == person.user), that if clause is NOT succeeding. Can you tell me why? Does one of the two really include gmail.com and the other does not?
2012-07-17 15:39:19.993 6 person schott.brian
I 2012-07-17 15:39:19.993 6 key ag1zfnBhcnRpY2lwb2xschMLEgJQUSILY29kZUJTY2hvdHQM
I 2012-07-17 15:39:19.993 6 ID_id codeBSchott
I 2012-07-17 15:39:19.993 6 user schott.brian
I 2012-07-17 15:39:19.993 7 user schott.brian
I 2012-07-17 15:39:19.994 7 person schott.brian
Upvotes: 1
Views: 381
Reputation: 8471
user.get_current_user()
returns an object. Printing the user casts it to a string, so maybe you want to do something like:
if user and (str(user) == str(person.user)):
but you're actually better off comparing user ids, rather than string representations of user objects.
Upvotes: 7