Access to deleted entity in Appengine NDB
Question: I am using NDB in an Appengine project. I am using _post_delete_hook for doing
some operations after some entity is deleted. In this method I have the key.
But when I do key.get() I get an error. Here is some example code.

    
    
    [friends/models.py]
    
    from ndb import models
    from users.models import User
    
    class FriendShip(models.Model):
        user = models.KeyProperty(kind=User)
        friend = models.KeyProperty(kind=User)
    
        @classmethod
        def _post_delete_hook(cls, key, future):
            signals.post_delete.send(cls, instance=key)
    
    [some-other-filer.py]
    
    # connected method to post_detele_hook
    def ended_friendship(sender, **kwargs):
        key = kwargs.get('instance', None)
        if key:
            user = key.get().user # raise a non existing entity error
    

Some help?

This is the doc about hooks.
<http://code.google.com/appengine/docs/python/ndb/entities.html#hooks>


Answer: For your use case (wanting to access the entity in your method), a
_pre_delete_hook might make more sense. See
<http://code.google.com/appengine/docs/python/ndb/modelclass.html#Model__pre_delete_hook>
.

