1
votes

I am working on a web app based on Google App Engine (Webapp2/Python and ndb). I am using the Google OAuth2 authentication and storing in a custom User Entity of my ndb the googleId I get through users.get_current_user().user_id(). Thus this entity has both a id (automatically provided by the ndb) and this property called googleId which is set by me. I use this user object as common ancestor of the other used data I store in the ndb.

This approach is quite annoying because to avoid multiple ndb queries (one for each request) I have to store in session the id of the currently logged user, its googled id AND verify whether it is different from the currently logged user.

I have therefore thought to use the googleId as the KEY of the ndb entity and use it in the ancestor queries. Like

 mu = MyUser(id = users.get_current_user().user_id())
 mu.put()

It works perfectly but I was wondering if there could be any valid reason not to do so (i.e. the googleId may be longer than the maximum size of the ndb id properties, etc.)

1

1 Answers

1
votes

I'd need to see your MyUser model (and maybe some other code) to be more confident, but, assuming that's all in a pretty normal arrangement, I don't think you'll run into any trouble.

Datastore ids can be pretty long, and the user_id, in turn, shouldn't be incredibly big anyway (it's unfortunate that neither limit is rigorously documented, but I personally wouldn't unduly worry about either).