浏览代码

HUE-8863 [catalog] Avoid UnboundLocalError: local variable 'data' referenced before assignment

Romain 6 年之前
父节点
当前提交
9ebc86afa7
共有 1 个文件被更改,包括 79 次插入79 次删除
  1. 79 79
      desktop/libs/metadata/src/metadata/catalog/atlas_client.py

+ 79 - 79
desktop/libs/metadata/src/metadata/catalog/atlas_client.py

@@ -205,91 +205,91 @@ class AtlasApi(Api):
     return self.fetch_single_entity('hive_column where %s' % qualifiedNameCriteria)
 
   def search_entities_interactive(self, query_s=None, limit=100, offset=0, facetFields=None, facetPrefix=None, facetRanges=None, filterQueries=None, firstClassEntitiesOnly=None, sources=None):
-    try:
-      response = {
-        "status": 0,
-        "results": [],
-        "facets": {
-          "tags": {}
-        }
+    response = {
+      "status": 0,
+      "results": [],
+      "facets": {
+        "tags": {}
       }
+    }
+
+    # This takes care of the list_tags endpoint
+    if not query_s and facetFields and 'tags' in facetFields:
+      classification_response = self._root.get('/v2/types/typedefs?type=classification')
+      for classification_def in classification_response['classificationDefs']:
+        if ' ' in classification_def['name']:
+          response['facets']['tags']['"' + classification_def['name'] + '"'] = -1
+        else:
+          response['facets']['tags'][classification_def['name']] = -1
+      return response
 
-      # This takes care of the list_tags endpoint
-      if not query_s and facetFields and 'tags' in facetFields:
-        classification_response = self._root.get('/v2/types/typedefs?type=classification')
-        for classification_def in classification_response['classificationDefs']:
-          if ' ' in classification_def['name']:
-            response['facets']['tags']['"' + classification_def['name'] + '"'] = -1
-          else:
-            response['facets']['tags'][classification_def['name']] = -1
-        return response
-
-      query_s = (query_s.strip() if query_s else '').replace('*', '')
-
-      atlas_type = None
-      classification = None
-      owner = None
-
-      # Take the first classification and type facets and ignore other as we can't search multiple in Atlas.
-      classification_facets = self.CLASSIFICATION_RE.findall(query_s)
-      if classification_facets:
-        classification = classification_facets[0][0] or classification_facets[0][1]
-        query_s = self.CLASSIFICATION_RE.sub('', query_s).strip()
-        atlas_type = 'Asset'  # Filtered below to just contain hive_db, hive_table or hive_column
-
-      owner_facets = self.OWNER_RE.findall(query_s)
-      if owner_facets:
-        owner = owner_facets[0]
-        query_s = self.OWNER_RE.sub('', query_s).strip()
-
-      type_facets = self.TYPE_RE.findall(query_s)
-      if type_facets:
-        atlas_type = self.NAV_TO_ATLAS_TYPE[type_facets[0].lower()] or type_facets[0]
-        query_s = self.TYPE_RE.sub('', query_s).strip()
-
-      data = {
-        'attributes': None,
-        'classification': classification,
-        'entityFilters': {
-          'condition': 'AND',
+    query_s = (query_s.strip() if query_s else '').replace('*', '')
+
+    atlas_type = None
+    classification = None
+    owner = None
+
+    # Take the first classification and type facets and ignore other as we can't search multiple in Atlas.
+    classification_facets = self.CLASSIFICATION_RE.findall(query_s)
+    if classification_facets:
+      classification = classification_facets[0][0] or classification_facets[0][1]
+      query_s = self.CLASSIFICATION_RE.sub('', query_s).strip()
+      atlas_type = 'Asset'  # Filtered below to just contain hive_db, hive_table or hive_column
+
+    owner_facets = self.OWNER_RE.findall(query_s)
+    if owner_facets:
+      owner = owner_facets[0]
+      query_s = self.OWNER_RE.sub('', query_s).strip()
+
+    type_facets = self.TYPE_RE.findall(query_s)
+    if type_facets:
+      atlas_type = self.NAV_TO_ATLAS_TYPE[type_facets[0].lower()] or type_facets[0]
+      query_s = self.TYPE_RE.sub('', query_s).strip()
+
+    data = {
+      'attributes': None,
+      'classification': classification,
+      'entityFilters': {
+        'condition': 'AND',
+        'criterion': [{
+          'condition': 'OR',
           'criterion': [{
-            'condition': 'OR',
-            'criterion': [{
-              'attributeName': 'name',
-              'attributeValue': query_s,
-              'operator': 'contains'
-            }, {
-              'attributeName': 'description',
-              'attributeValue': query_s,
-              'operator': 'contains'
-            }]
+            'attributeName': 'name',
+            'attributeValue': query_s,
+            'operator': 'contains'
+          }, {
+            'attributeName': 'description',
+            'attributeValue': query_s,
+            'operator': 'contains'
           }]
-        },
-        'excludeDeletedEntities': True,
-        'includeClassificationAttributes': True,
-        'includeSubClassifications': True,
-        'includeSubTypes': True,
-        'limit': limit,
-        'offset': 0,
-        'tagFilters': None,
-        'termName': None,
-        'typeName': atlas_type or 'hive_table'
-      }
-
-      if get_catalog_search_cluster():
-        data['entityFilters']['criterion'].append({
-          'attributeName': 'qualifiedName',
-          'operator': 'contains',
-          'attributeValue': '@' + get_catalog_search_cluster()
-        })
+        }]
+      },
+      'excludeDeletedEntities': True,
+      'includeClassificationAttributes': True,
+      'includeSubClassifications': True,
+      'includeSubTypes': True,
+      'limit': limit,
+      'offset': 0,
+      'tagFilters': None,
+      'termName': None,
+      'typeName': atlas_type or 'hive_table'
+    }
 
-      if owner:
-        data['entityFilters']['criterion'].append({
-          'attributeName': 'owner',
-          'operator': 'startsWith',
-          'attributeValue': owner
-        })
+    if get_catalog_search_cluster():
+      data['entityFilters']['criterion'].append({
+        'attributeName': 'qualifiedName',
+        'operator': 'contains',
+        'attributeValue': '@' + get_catalog_search_cluster()
+      })
+
+    if owner:
+      data['entityFilters']['criterion'].append({
+        'attributeName': 'owner',
+        'operator': 'startsWith',
+        'attributeValue': owner
+      })
 
+    try:
       atlas_response = self._root.post('/v2/search/basic', data=json.dumps(data), contenttype=_JSON_CONTENT_TYPE)
 
       # Adapt Atlas entities to Navigator structure in the results