2

Trying to figure out the best practice when storing Webapp2 Auth user objects as a reference in a google app engine ndb domain entity.

The 3 ways I can think to do it

class MyEntity(ndb.Model):
  users = ndb.UserProperty(repeated=True)

or

class MyEntity(ndb.Model):
  users = ndb.StringProperty(repeated=True)

where I would store user id's from the webapp2 User object like

user.get_id()

or

class MyEntity(ndb.Model):
  users = ndb.KeyProperty(repeated=True)

where I would store user key from the webapp2 User object like

user.key

I am not sure what is the best practice here? In particular is there any advantage to storing user_id vs key? Assuming UserProperty is the old way of doing things?

dboyd68
  • 1,104
  • 15
  • 33

1 Answers1

3

Avoid UserProperty, store the ID instead.

Straight from the source...

# google/appengine/ext/ndb/model.py:1711

class UserProperty(Property):
  """A Property whose value is a User object.

  Note: this exists for backwards compatibility with existing
  datastore schemas only; we do not recommend storing User objects
  directly in the datastore, but instead recommend storing the
  user.user_id() value.
  """
jdiaz5513
  • 168
  • 1
  • 9
  • Is the id better than the key, because they also have KeyProperty (allowing to specify specific types) would have thought storing the key better? – dboyd68 Mar 13 '13 at 08:02
  • 1
    The ID is what uniquely identifies the user, the Key can be implementation-specific. – jdiaz5513 Mar 14 '13 at 00:36