소스 검색

HUE-4621 [core] On loaddata failure, print stdout to logs

Jenny Kim 9 년 전
부모
커밋
7c3324d
1개의 변경된 파일9개의 추가작업 그리고 6개의 파일을 삭제
  1. 9 6
      desktop/core/src/desktop/api2.py

+ 9 - 6
desktop/core/src/desktop/api2.py

@@ -17,8 +17,8 @@
 
 import logging
 import json
-import tempfile
 import StringIO
+import tempfile
 import zipfile
 
 from datetime import datetime
@@ -423,23 +423,26 @@ def import_documents(request):
 
     # If the doc contains any history dependencies, ignore them
     # NOTE: this assumes that each dependency is exported as an array using the natural PK [uuid, version, is_history]
-    deps_minus_history = [dep for dep in doc.get('dependencies', []) if len(dep) >= 3 and not dep[2]]
-    doc['dependencies'] = deps_minus_history
+    deps_minus_history = [dep for dep in doc['fields'].get('dependencies', []) if len(dep) >= 3 and not dep[2]]
+    doc['fields']['dependencies'] = deps_minus_history
 
     # Set last modified date to now
     doc['fields']['last_modified'] = datetime.now().replace(microsecond=0).isoformat()
     docs.append(doc)
 
   f = tempfile.NamedTemporaryFile(mode='w+', suffix='.json')
-
   f.write(json.dumps(docs))
   f.flush()
 
   stdout = StringIO.StringIO()
   try:
-    management.call_command('loaddata', f.name, stdout=stdout)
+    management.call_command('loaddata', f.name, verbosity=2, traceback=True, stdout=stdout)
   except Exception, e:
-    return JsonResponse({'message': smart_str(e)})
+    stdout.seek(0)
+    LOG.error('Failed to run loaddata command in import_documents:\n %s' % stdout.read())
+    return JsonResponse({'status': -1, 'message': smart_str(e)})
+  finally:
+    stdout.close()
 
   Document.objects.sync()