when saving an object with reference properties, does the application respond to checking that the objects referenced by the link properties already exist in the data store? During unit testing with datastore_v3_stub, I found that the application engine would happily save the object A associated with it with the reference property B (and B does not yet exist in the data store). further, when A is saved, B is not saved. When you subsequently retrieve A from the data store and try to go to B, you get an exception. Is this expected behavior?
Code example:
user = MyUser(key_name='2', name='my user 2') e = db.get(user.key()) self.assertTrue(e is None)
EDIT: I'm new to python, but is it possible to write a class that subclasses db.Model and overrides the put method to provide referential integrity (using some kind of reflection) before calling put db.Model. Then I can simply subclass this class to provide referential integrity in my model classes (e.g. A, B)
that's what i came up with. can any guru code revise this:
for name, property in obj.properties().items(): if isinstance(property, db.ReferenceProperty): try: value = getattr(essay, name) except datastore_errors.Error: print name, property, 'does not exist in datastore yet' continue key = value.key() o = db.get(key) if o is None: print name, property, value, 'does not exist in datastore yet'
source share