Chris Marasti-Georg
Chris Marasti-Georg

Reputation: 34680

How do I change the user associated with a datastore record in GAE?

I have a user who changed the email address associated with his Google account. He is no longer associated with datastore records that used to be associated with his User object.

Can I just update the user property on the datastore objects with his new email address? Do I need to construct an actual User object to query or update these records, and if so, should I be using email, nickname, or user_id?

I am using Python if it matters.

Upvotes: 0

Views: 77

Answers (2)

Chris Marasti-Georg
Chris Marasti-Georg

Reputation: 34680

A snippet of the solution that ended up working for me:

    old_user = users.User(email="[email protected]");
    new_user = users.User(email="[email protected]");
    changed = []

    things = model.Ball.all().filter("user =", old_user).fetch(500);
    for thing in things:
        thing.user = new_user
        changed += [thing]

    if len(changed) >= 500:
        db.put(changed)
        return

    ...

Upvotes: 0

voscausa
voscausa

Reputation: 11706

From the docs: If the email address is associated with a Google account, user_id returns the unique permanent ID of the user, a str. This ID is always the same for the user regardless of whether the user changes her email address.

Upvotes: 2

Related Questions