瀏覽代碼

[desktop] Support importing search dashboard format from Hue 3.7

Some old documents are creating a KeyError: 'collection'
Romain Rigaux 9 年之前
父節點
當前提交
6374a71
共有 1 個文件被更改,包括 14 次插入13 次删除
  1. 14 13
      desktop/core/src/desktop/models.py

+ 14 - 13
desktop/core/src/desktop/models.py

@@ -327,19 +327,20 @@ class DocumentManager(models.Manager):
       if Collection._meta.db_table in table_names:
         with transaction.atomic():
           for dashboard in Collection.objects.all():
-            col_dict = dashboard.properties_dict['collection']
-            if not 'uuid' in col_dict:
-              _uuid = str(uuid.uuid4())
-              col_dict['uuid'] = _uuid
-              dashboard.update_properties({'collection': col_dict})
-              if dashboard.owner is None:
-                from useradmin.models import install_sample_user
-                owner = install_sample_user()
-              else:
-                owner = dashboard.owner
-              dashboard_doc = Document2.objects.create(name=dashboard.label, uuid=_uuid, type='search-dashboard', owner=owner, description=dashboard.label, data=dashboard.properties)
-              Document.objects.link(dashboard_doc, owner=owner, name=dashboard.label, description=dashboard.label, extra='search-dashboard')
-              dashboard.save()
+            if 'collection' in dashboard.properties_dict:
+              col_dict = dashboard.properties_dict['collection']
+              if not 'uuid' in col_dict:
+                _uuid = str(uuid.uuid4())
+                col_dict['uuid'] = _uuid
+                dashboard.update_properties({'collection': col_dict})
+                if dashboard.owner is None:
+                  from useradmin.models import install_sample_user
+                  owner = install_sample_user()
+                else:
+                  owner = dashboard.owner
+                dashboard_doc = Document2.objects.create(name=dashboard.label, uuid=_uuid, type='search-dashboard', owner=owner, description=dashboard.label, data=dashboard.properties)
+                Document.objects.link(dashboard_doc, owner=owner, name=dashboard.label, description=dashboard.label, extra='search-dashboard')
+                dashboard.save()
     except Exception, e:
       LOG.exception('error syncing search')