Browse Source

[core] getting complete snippet for close_statement call (#2777)

Ayush Goyal 3 years ago
parent
commit
0128288860
1 changed files with 5 additions and 3 deletions
  1. 5 3
      desktop/libs/notebook/src/notebook/api.py

+ 5 - 3
desktop/libs/notebook/src/notebook/api.py

@@ -406,7 +406,7 @@ def cancel_statement(request):
   response = {'status': -1}
 
   notebook = json.loads(request.POST.get('notebook', '{}'))
-  snippet = {}
+  snippet = json.loads(request.POST.get('snippet', '{}'))
   operation_id = request.POST.get('operationId') or notebook['uuid']
 
   snippet = _get_snippet(request.user, notebook, snippet, operation_id)
@@ -713,7 +713,7 @@ def close_statement(request):
   response = {'status': -1}
 
   notebook = json.loads(request.POST.get('notebook', '{}'))
-  snippet = {}
+  snippet = json.loads(request.POST.get('snippet', '{}'))
   operation_id = request.POST.get('operationId')
 
   if operation_id and not notebook.get('uuid'):
@@ -1045,7 +1045,9 @@ def describe(request, database, table=None, column=None):
 
 
 def _get_snippet(user, notebook, snippet, operation_id):
-  if operation_id or not snippet:
+  # snippet is not complete so we are extracting it again for the editor call
+  snippet_has_guid = snippet.get('result') and snippet['result'].get('handle') and snippet['result']['handle'].get('guid')
+  if operation_id or not snippet or not snippet_has_guid:
     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]