I'm running into a frequent AttributeError: 'Document' object has no attribute '_key_name'
Error when I try to delete multiple documents from the datastore (same entity group). This error only occurs when the delete request first runs into a "Transaction collision". So for example I send these three delete requests in quick succession: DELETE /v1/documents/1-62?version=0 DELETE /v1/documents/1-1071?version=0 DELETE /v1/documents/1-64?version=0 The first two requests work fine. But in this case the third dumps a Transaction collision and then a "no attribute '_key_name" stack trace in the logs, and the delete fails to take place: 03-13 05:32AM 48.567 /v1/documents/1-1071?version=0 500 881ms 675ms- cpu 1kb WriteRoom/1.3.1 CFNetwork/342.1 Darwin/9.4.1,gzip(gfe) 64.222.203.28 - jesse [13/Mar/2009:05:32:49 -0700] "DELETE /v1/ documents/1-1071?version=0 HTTP/1.1" 500 1406 - "WriteRoom/1.3.1 CFNetwork/342.1 Darwin/9.4.1,gzip(gfe)" W 03-13 05:32AM 49.421 Transaction collision for entity group with key datastore_types.Key.from_path('Account', 1L, _app=u'hogbaywriteroom'). Retrying... E 03-13 05:32AM 49.422 'Document' object has no attribute '_key_name' Traceback (most recent call last): File "/base/python_lib/versions/1/google/appengine/ext/webapp/ __init__.py", line 511, in __call__ handler.delete(*groups) File "/base/data/home/apps/hogbaywriteroom/1.332025726958922683/ documents.py", line 168, in g return f(*new_args, **kw) File "/base/data/home/apps/hogbaywriteroom/1.332025726958922683/ documents.py", line 198, in g return f(*new_args, **kw) File "/base/data/home/apps/hogbaywriteroom/1.332025726958922683/ documents.py", line 492, in delete db.run_in_transaction(txn) File "/base/python_lib/versions/1/google/appengine/api/ datastore.py", line 1654, in RunInTransaction DEFAULT_TRANSACTION_RETRIES, function, *args, **kwargs) File "/base/python_lib/versions/1/google/appengine/api/ datastore.py", line 1745, in RunInTransactionCustomRetries result = function(*args, **kwargs) File "/base/data/home/apps/hogbaywriteroom/1.332025726958922683/ documents.py", line 482, in txn deleted = Deleted(parent=document.parent_key(), document_key=str (document.key())) File "/base/python_lib/versions/1/google/appengine/ext/db/ __init__.py", line 616, in key elif self._key_name: AttributeError: 'Document' object has no attribute '_key_name' The problem doesn't seem related to the documents server state. Right after that above failure I sent the same delete request again, and it worked fine that time. So I'm 99 percent sure that the cause is the transaction collision, but I'm not sure how to resolve it. Quite possibly I'm doing something wrong in my code, here's when my delete method looks like. If you need to see more code I'd be happy to provide the @require_document code to. Just let me know. @require_document def delete(self, user_account, document_account, document): version = self.request.get('version', None) version = None if version == None else int(version) if version == None: self.error(400) return def txn(): if version != document.version: raise ValueError, "Version does not match document version" deleted = Deleted(parent=document.parent_key(), document_key=str (document.key())) document_account.documents_size -= document.edits_size id_string = document.id_string() account_emails = document.get_account_emails() deleted.put() document.delete() document_account.put() clear_memcache(id_string, account_emails) try: document_id = document.key().id() db.run_in_transaction(txn) for edit in Edit.gql("WHERE ANCESTOR IS :1", db.Key.from_path ('Account', document_account.key().id(), 'Document', document_id)): edit.delete() if not api(self.request): self.redirect('/documents', False) except ValueError: self.error(409) except db.TransactionFailedError: self.error(409) Thanks for your help. Jesse --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---