Quellcode durchsuchen

[api] Fix /get_logs and /fetch_result_size public APIs (#2749)

- Added "properties" field in notebook's snippet.
- Fetch notebook for both APIs using operation_id in core API implementation. This is required keeping public APIs in mind because we only send "operationId" as param for public API which is not the case via Hue UI calls.
Harsh Gupta vor 3 Jahren
Ursprung
Commit
3bb0ada598
2 geänderte Dateien mit 14 neuen und 2 gelöschten Zeilen
  1. 1 1
      desktop/core/src/desktop/api_public.py
  2. 13 1
      desktop/libs/notebook/src/notebook/api.py

+ 1 - 1
desktop/core/src/desktop/api_public.py

@@ -88,7 +88,7 @@ def execute(request, dialect=None):
 
     data = {
       'notebook': '{"type":"query-%(interpreter)s","snippets":[{"id":%(interpreter_id)s,"statement_raw":"",'
-        '"type":"%(interpreter)s","status":"","variables":[]}],'
+        '"type":"%(interpreter)s","status":"","variables":[],"properties":{}}],'
         '"name":"","isSaved":false,"sessions":[]}' % params,
       'snippet': '{"id":%(interpreter_id)s,"type":"%(interpreter)s","result":{},"statement":"%(statement)s","properties":{}}' % params
     }

+ 13 - 1
desktop/libs/notebook/src/notebook/api.py

@@ -382,6 +382,7 @@ def fetch_result_size(request):
   notebook = json.loads(request.POST.get('notebook', '{}'))
   snippet = json.loads(request.POST.get('snippet', '{}'))
 
+  notebook = _get_notebook(request.user, notebook, operation_id)
   snippet = _get_snippet(request.user, notebook, snippet, operation_id)
 
   with opentracing.tracer.start_span('notebook-fetch_result_size') as span:
@@ -434,7 +435,9 @@ def get_logs(request):
   notebook = json.loads(request.POST.get('notebook', '{}'))
   snippet = json.loads(request.POST.get('snippet', '{}'))
 
-  if operation_id:
+  notebook = _get_notebook(request.user, notebook, operation_id)
+
+  if operation_id and not notebook.get('uuid'):
     notebook['uuid'] = operation_id
 
   startFrom = request.POST.get('from')
@@ -1046,4 +1049,13 @@ def _get_snippet(user, notebook, snippet, operation_id):
     nb_doc = Document2.objects.get_by_uuid(user=user, uuid=operation_id or notebook.get('uuid'))
     notebook = Notebook(document=nb_doc).get_data()
     snippet = notebook['snippets'][0]
+
   return snippet
+
+
+def _get_notebook(user, notebook, operation_id):
+  if operation_id and not notebook:
+    nb_doc = Document2.objects.get_by_uuid(user=user, uuid=operation_id)
+    notebook = Notebook(document=nb_doc).get_data()
+
+  return notebook