user objects different based on email case?

7 views
Skip to first unread message

Savraj Singh

unread,
Aug 28, 2008, 12:35:36 PM8/28/08
to Google App Engine
Hi everyone, quick question.

class Tests(webapp.RequestHandler):
def get(self):
user1 = users.User(email="sav...@gmail.com")
user2 = users.User(email="Sav...@gmail.com")

if user1 == user2:
self.response.out.write("users are the same")
else:
self.response.out.write("users are different")

The result is that "users are different" -- I'm surprised by that.
Shouldn't they be the same? Especially savraj and Savraj both point to
my valid google account? I can work around this issue but according
to the API documentation I would assume that user1 and user2 are
equal.

Thanks for your help!

-Savraj

Message has been deleted

Savraj Singh

unread,
Aug 28, 2008, 4:53:09 PM8/28/08
to Google App Engine
Yes, I can do that, thanks -- but I still think this behavior is a
problem.

Let's say I create a datastore model:

class UserInfo(db.Model):
owner = db.UserProperty()
Info = db.StringProperty()

Now let's say I create a UserInfo entity with owner set as user1 and
save it to the datastore.

I can't look up this saved entity unless I match the case of the
original email address (user2 will not match it). That's the problem.

I discovered this problem because when I assign owners in parts of my
application, sometimes Google capitalizes the email addresses, and
other times, it does not.

I can resort to using strings, but that defeats the purpose of having
a special 'userProperty' that abstracts away this stuff.

Thanks for your help, everyone.

- s


On Aug 28, 4:30 pm, Davide Rognoni <davide.rogn...@gmail.com> wrote:
> str(user1).lower() == str(user2).lower()

Alexander Kojevnikov

unread,
Aug 28, 2008, 7:48:51 PM8/28/08
to Google App Engine
As far as I can see, there's very little point in storing User
instances constructed from an e-mail address. These instances don't
correspond to real Google accounts, GAE doesn't do anything special to
verify the validity of supplied e-mail addresses, and basically it
just stores the e-mail addresses as strings.

If you want your User instances to correspond to real accounts you
need to use users.get_current_user(). If not, I suppose it's less
confusing to just store the (lower-cased) e-mail addresses in a string
property.

Savraj Singh

unread,
Aug 29, 2008, 12:18:31 AM8/29/08
to Google App Engine
Hi Alexander,

Yes, that's how I'm storing the users. Let's say I have five users
that all store UserInfo. I call users.get_current_user() to get the
user and then save the Info. My problem is accessing a user's
information again, when that user is not logged in.

The documentation says, "A User object with an email address that
doesn't correspond to a valid Google account can be stored in the
datastore, but will never match a real user." That implies to me that
a user object with an email address that does correspond to a valid
google account will match a real user. But I guess that's too much of
a leap? What's the point of these user objects constructed from emails
if they don't match real users?

Again thank you all for reading -- I'll come up with some other
strategy to approach this.

- savraj




On Aug 28, 7:48 pm, Alexander Kojevnikov <alexan...@kojevnikov.com>
wrote:

Alexander Kojevnikov

unread,
Aug 29, 2008, 1:29:44 AM8/29/08
to Google App Engine
> What's the point of these user objects constructed from emails
> if they don't match real users?

I guess this is mostly for testing / debugging, for example the SDK
version of the Users API always authenticates e-mail-constructed User
instances.

ryan

unread,
Aug 29, 2008, 3:32:57 AM8/29/08
to Google App Engine
this is the expected behavior, since the "local" part of an email
address, aka the username, is case sensitive.

http://en.wikipedia.org/wiki/E-mail_address#RFC_Specification

i tried to find somewhere in rfc 2822 that says this, but it doesn't
actually talk about case sensitivity. it just punts and says that it's
domain dependent. :P

http://tools.ietf.org/html/rfc2822#section-3.4.1

for app engine purposes, the key point is that the primary email
address on a google account can have any domain. it doesn't have to be
gmail.com, googlemail.com, or even a google apps domain. given that,
we have to be conservative and consider the local part of the email
adress as case sensitive.
Reply all
Reply to author
Forward
0 new messages