When running mapreduce on Google App Engine, I occasionally come across a key reference that is invalid. I'd like to make an efficient method that I could run across any model using mapreduce to verify that all the key references for each entity are still valid. What would be the most efficient way to do this? Here is my map function idea so far.
#map function
def check_all_references(entity):
for attr, value in entity.__dict__.iteritems():
if type(value)== #google.appengine.api.datastore_types.Key:
#Check to see if the referenced entity exists
....
if referencedEntityExists: return
else:
logging.error('Entity %s referenced entity %s which is not valid.', entity, referencedEntity)