Browse Source

HUE-8320 [core] After copying a workflow using Hue 4 button, saving the copied workflow fails

Roohi 7 years ago
parent
commit
2592be118d
2 changed files with 10 additions and 3 deletions
  1. 7 2
      desktop/core/src/desktop/api2.py
  2. 3 1
      desktop/core/src/desktop/tests_doc2.py

+ 7 - 2
desktop/core/src/desktop/api2.py

@@ -371,16 +371,21 @@ def copy_document(request):
   if not uuid:
     raise PopupException(_('copy_document requires uuid'))
 
+
+  # Document2 and Document model objects are linked and both are saved when saving
   document = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)
+  # Document model object
+  document1 = document.doc.get()
 
   if document.type == 'directory':
     raise PopupException(_('Directory copy is not supported'))
 
-
   name = document.name + '-copy'
 
-  # Make the copy of the new Document
+  # Make the copy of the Document2 model object
   copy_document = document.copy(name=name, owner=request.user)
+  # Make the copy of Document model object too
+  document1.copy(content_object=copy_document, name=name, owner=request.user)
 
   # Import workspace for all oozie jobs
   if document.type == 'oozie-workflow2' or document.type == 'oozie-bundle2' or document.type == 'oozie-coordinator2':

+ 3 - 1
desktop/core/src/desktop/tests_doc2.py

@@ -30,7 +30,7 @@ from desktop.converters import DocumentConverter
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.fs import ProxyFS
 from desktop.lib.test_utils import grant_access
-from desktop.models import Directory, Document2
+from desktop.models import Directory, Document2, Document
 from notebook.models import import_saved_beeswax_query
 
 from beeswax.models import SavedQuery
@@ -178,6 +178,8 @@ class TestDocument2(object):
 
     workflow_doc = Document2.objects.create(name='Copy Test', type='oozie-workflow2', owner=self.user, data={},
                                             parent_directory=self.home_dir)
+    Document.objects.link(workflow_doc, owner=workflow_doc.owner, name=workflow_doc.name,
+                          description=workflow_doc.description, extra='workflow2')
 
     workflow = Workflow(user=self.user)
     workflow.update_name('Copy Test')