views:

38

answers:

3

In an App Engine app, I store registered members in a table that looks like this:

class Member(db.Model):
    user = db.UserProperty(required=True)
    #other stuff

The problem starts when I need to check if a User is already in my Member table. GAE documentation says user value is not guaranteed not to change in time since it is composed by the user object+email. So it will change if the user changes the e-mail on that account.

I am using OpenID. So I though about using User.federated_identity() as a stable identifier.

However to check for this I'd have to do a Query like this:

u = users.get_current_user()
rm = Member.all().filter('user_federated_identity =',u.federated_identity()).get()

This is a valid query in Django, but apparenty not in GAE. What can I do here, other that loading all my members to memory and checking their federated_identity?

A: 

GAE User API explicitly mentions user_id() as a permanent identifier that persists across e-mail changes. You can store it in separate field in model.

Note that it is only supported for Google Accounts.

Xion
That' why I can't use it...it does not support OpenID users
fccoelho
True, my bad. But in that case you should store federated_identity() and federated_provider() as separate fields. Unfortunately GAE datastore does not support queries based on property values' attribute values.
Xion
A: 

Hello,

Maybe you can identify your user by a unique key_name:

key_name = "member/%s" % users.get_current_user ().user_id
user_ref = Member.get_or_insert (key_name)
sahid
+1  A: 

You should be able to do this:

u = users.get_current_user()
rm = Member.all().filter('user =', u).get()
Drew Sears