Przeglądaj źródła

HUE-3976 [doc2] Exporting doc dependencies should not include history docs

Jenny Kim 9 lat temu
rodzic
commit
e4acf9d

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

@@ -434,7 +434,7 @@ def import_documents(request):
 def _get_dependencies(documents, deps_mode=True):
   """
   Given a list of Document2 objects, perform a depth-first search and return a set of documents with all
-   dependencies included
+   dependencies (excluding history docs) included
   :param doc_set: set of Document2 objects to include
   :param deps_mode: traverse dependencies relationship, otherwise traverse children relationship
   """
@@ -444,7 +444,7 @@ def _get_dependencies(documents, deps_mode=True):
     stack = [doc]
     while stack:
       curr_doc = stack.pop()
-      if curr_doc not in doc_set:
+      if curr_doc not in doc_set and not curr_doc.is_history:
         doc_set.add(curr_doc)
         if deps_mode:
           deps_set = set(curr_doc.dependencies.all())

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

@@ -795,11 +795,13 @@ class TestDocument2ImportExport(object):
   def test_export_documents_with_dependencies(self):
     query1 = Document2.objects.create(name='query1.sql', type='query-hive', owner=self.user, data={}, parent_directory=self.home_dir)
     query2 = Document2.objects.create(name='query2.sql', type='query-hive', owner=self.user, data={}, parent_directory=self.home_dir)
+    query3 = Document2.objects.create(name='query3.sql', type='query-hive', owner=self.user, data={}, parent_directory=self.home_dir, is_history=True)
     workflow = Document2.objects.create(name='test.wf', type='oozie-workflow2', owner=self.user, data={}, parent_directory=self.home_dir)
     workflow.dependencies.add(query1)
     workflow.dependencies.add(query2)
+    workflow.dependencies.add(query3)
 
-    # Test that exporting workflow should export all dependencies
+    # Test that exporting workflow should export all dependencies except history
     response = self.client.get('/desktop/api2/doc/export/', {'documents': json.dumps([workflow.id]), 'format': 'json'})
     documents = json.loads(response.content)
     documents = json.loads(documents)
@@ -808,6 +810,7 @@ class TestDocument2ImportExport(object):
     assert_true('test.wf' in [doc['fields']['name'] for doc in documents])
     assert_true('query1.sql' in [doc['fields']['name'] for doc in documents])
     assert_true('query2.sql' in [doc['fields']['name'] for doc in documents])
+    assert_false('query3.sql' in [doc['fields']['name'] for doc in documents])
 
     # Test that exporting multiple workflows with overlapping dependencies works
     workflow2 = Document2.objects.create(name='test2.wf', type='oozie-workflow2', owner=self.user, data={}, parent_directory=self.home_dir)