python - How to identify objects with broken reference properties in google app engine -
how correctly check broken reference properties in google app engine?
example:
class user (db.model): username = db.stringproperty(multiline=false) class foo (db.model): user = db.referenceproperty(user, collection_name="user_foo")
- a user object created.
- a foo object created.
- the corresponding reference property in user deleted.
as suggested daniel roseman in comments:
"iterate through foos , access item.user, , [check] if resolveerror raised"
from google.appengine.api import datastore_errors all_foo = foo.all() bar in all_foo: try: user_refproperty = bar.user except datastore_errors.error, e: if e.args[0][0:40] == "referenceproperty failed resolved:": bar.delete() self.response.out.write('deleted due bad reference property') else: raise
Comments
Post a Comment