The Google App Engine ndb provides _post_put_hook(self, future) , documented as follows:
The hook that starts after put ()
To understand this hook better, I wonder when self will be different from the result of the future argument.
Model Hooks documentation provides:
If you use post-hooks with asynchronous APIs, hooks are triggered by calling check_result (), get_result () or receiving (inside the tasklet) an asynchronous use method in the future. Post-hooks do not check if the RPC was successful; The hook works regardless of failure.
All post-hooks have a Future argument at the end of the call signature. This Future object contains the result of the action. You can call get_result () in this Future to get the result; you can be sure that get_result () will not be blocked, since the future will be completed by the time the hook is called.
However, when I call put asynchronously as follows:
from google.appengine.ext import ndb class MyModel(ndb.Model): xyz = ndb.StringProperty() def _post_put_hook(self, future): print "self.xyz: {}, future.xyz: {}".format( self.xyz, future.get_result().get().xyz)) m = MyModel() f = m.put_async() f.wait() m.xyz = 'abc' f = m.put_async() f.wait()
Outputs:
self.xyz: None, future.xyz: None self.xyz: abc, future.xyz: abc
In the context of "put_async", I think one would expect that self would be a model before modification, and future would become a model that is now saved. Otherwise, it is not clear what the future goal would be in the context of put .
When will self and future differ in the context of put ? What is the future goal here?