I've got some models on my GAE app, and I've overriden put()
on some of them. When I call db.put()
with a list of these entites, is there a guarantee that the overriden put()
on each entity will be called?
What I开发者_StackOverflow中文版'm seeing right now is that the entities are just getting saved without it being called. Is there any good way to make sure stuff is done before every save, even batches?
No. You need to monkeypatch db.put()
too. For a good example of this, check out Nick Johnson's excellent blog post on Pre- and post- put hooks for Datastore models.
If you look at the source code for the db
module, you'll see that db.put()
does not call the entity's put()
function.
You could try something like:
class SomeModel(db.Model):
aprop = db.IntegerProperty()
def _populate_internal_entity(self, *args, **kwargs):
logging.warn('about to Put() SomeModel: %r', self)
return super(SomeModel, self)._populate_internal_entity(*args, **kwargs)
However, there is probably a better way to do it. If you are trying to set some properties you should check out custom property classes. If you are trying to do logging or caching you should investigate datastore hooks.
精彩评论