Browse Source

HUE-4631 [home] Prevent TransactionManagementError resulting from history document conversion failure

Currently all other document conversions use _create_doc2() which is wrapped
by atomic block except history document conversion which uses _historify()
krish 8 years ago
parent
commit
f42bbf0ae1
1 changed files with 21 additions and 20 deletions
  1. 21 20
      desktop/core/src/desktop/converters.py

+ 21 - 20
desktop/core/src/desktop/converters.py

@@ -87,26 +87,27 @@ class DocumentConverter(object):
           data['isSaved'] = False
           data['snippets'][0]['lastExecuted'] = time.mktime(doc.last_modified.timetuple()) * 1000
 
-          doc2 = _historify(data, self.user)
-          doc2.last_modified = doc.last_modified
-
-          # save() updates the last_modified to current time. Resetting it using update()
-          doc2.save()
-          Document2.objects.filter(id=doc2.id).update(last_modified=doc.last_modified)
-
-          self.imported_docs.append(doc2)
-
-          # Tag for not re-importing
-          Document.objects.link(
-            doc2,
-            owner=doc2.owner,
-            name=doc2.name,
-            description=doc2.description,
-            extra=doc.extra
-          )
-
-          doc.add_tag(self.imported_tag)
-          doc.save()
+          with transaction.atomic():
+            doc2 = _historify(data, self.user)
+            doc2.last_modified = doc.last_modified
+
+            # save() updates the last_modified to current time. Resetting it using update()
+            doc2.save()
+            Document2.objects.filter(id=doc2.id).update(last_modified=doc.last_modified)
+
+            self.imported_docs.append(doc2)
+
+            # Tag for not re-importing
+            Document.objects.link(
+              doc2,
+              owner=doc2.owner,
+              name=doc2.name,
+              description=doc2.description,
+              extra=doc.extra
+            )
+
+            doc.add_tag(self.imported_tag)
+            doc.save()
     except ImportError, e:
       LOG.warn('Cannot convert Saved Query documents: beeswax app is not installed')