Your setter is being called, and it is causing the behavior you don't want. Tearing it down:
def IdSet(self, value):
if not isinstance(value, basestring):
raise TypeError('ID must be a string.')
self.caseful_id = value
self.UpdateFromKey(ndb.Key(self.__class__, value.lower()))
since you call
self.caseful_id = value
before UpdateFromKey
, the caseful_id
will always be the one from the most recent request.
Bear in mind that UpdateFromKey
tries to retrieve an entity by that key and then patches in any missing data from the entity stored in the datastore (and also sets from_datastore
to True
).
Since you set the caseful_id
field before UpdateFromKey
, there is no missing data. Instead, you could do this to set the value if not already set (and so this wouldn't be relevant for your 'GET'
method):
def IdSet(self, value):
if not isinstance(value, basestring):
raise TypeError('ID must be a string.')
self.UpdateFromKey(ndb.Key(self.__class__, value.lower()))
if self.caseful_id is None:
self.caseful_id = value