[converter] Delete Doc2 object incase of exception
Even though we have the atomic block, it is observed that when there is a mix of
InnoDB and MyIASM tables in mysql db, the behavior of atomic block is inconsistent.
@@ -236,6 +236,7 @@ class DocumentConverter(object):
def _create_doc2(self, document, doctype, name=None, description=None, data=None):
try:
+ document2 = None
with transaction.atomic():
name = name if name else document.name
@@ -265,4 +266,8 @@ class DocumentConverter(object):
document.save()
return document2
except Exception, e:
+ # Just to be sure we delete Doc2 object incase of exception.
+ # Possible when there are mixed InnoDB and MyISAM tables
+ if document2 and Document2.objects.filter(id=document2.id).exists():
+ document2.delete()
raise PopupException(_("Failed to convert Document object: %s") % e)
