Skip to content

Commit

Permalink
[editor] Fix a bug where saving an actual notebook has the incorrect …
Browse files Browse the repository at this point in the history
…document type (#3655)
  • Loading branch information
JohanAhlen authored Mar 14, 2024
1 parent 08037bd commit c8872fc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion desktop/libs/notebook/src/notebook/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ def get_logs(request):
return JsonResponse(response)

def _save_notebook(notebook, user):
if notebook['snippets'][0].get('connector') and notebook['snippets'][0]['connector'].get('dialect'): # TODO Connector unification
if notebook.get('type') != 'notebook' and notebook['snippets'][0].get('connector') and \
notebook['snippets'][0]['connector'].get('dialect'): # TODO Connector unification
notebook_type = 'query-%(dialect)s' % notebook['snippets'][0]['connector']
if notebook['snippets'][0] and notebook['snippets'][0].get('executor'):
notebook['snippets'][0]['executor']['executables'] = []
Expand Down
38 changes: 38 additions & 0 deletions desktop/libs/notebook/src/notebook/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,45 @@ def test_save_notebook(self):

# Test that saving a notebook will save the search field to the first statement text
assert_equal(doc.search, "select * from default.web_logs where app = 'metastore';")
assert_equal(doc.type, "query-hive")

def test_type_when_saving_an_actual_notebook(self):
notebook_json = """
{
"selectedSnippet": "hive",
"showHistory": false,
"description": "Test Notebook",
"name": "Test Notebook",
"sessions": [
{
"type": "hive",
"properties": [],
"id": null
}
],
"type": "notebook",
"id": null,
"snippets": [{"id":"2b7d1f46-17a0-30af-efeb-33d4c29b1055","type":"hive","status":"running","statement_raw":""" \
""""select * from default.web_logs where app = '${app_name}';","variables":""" \
"""[{"name":"app_name","value":"metastore"}],"statement":""" \
""""select 1;","properties":{"settings":[],"files":[],"functions":[]},""" \
""""result":{"id":"b424befa-f4f5-8799-a0b4-79753f2552b1","type":"table","handle":{"log_context":null,""" \
""""statements_count":1,"end":{"column":21,"row":0},"statement_id":0,"has_more_statements":false,""" \
""""start":{"column":0,"row":0},"secret":"rVRWw7YPRGqPT7LZ/TeFaA==an","has_result_set":true,""" \
""""statement":"select * from default.web_logs where app = 'metastore';","operation_type":0,""" \
""""modified_row_count":null,"guid":"7xm6"}},"lastExecuted": 1462554843817,"database":"default"}],
"uuid": "d9efdee1-ef25-4d43-b8f9-1a170f69a05a"
}
"""

response = self.client.post(reverse('notebook:save_notebook'), {'notebook': notebook_json})
data = json.loads(response.content)

assert_equal(0, data['status'], data)
assert_equal('notebook', data['type'], data)
doc = Document2.objects.get(pk=data['id'])

assert_equal(doc.type, "notebook")

def test_save_notebook_with_connector_off(self):
reset = ENABLE_CONNECTORS.set_for_testing(False)
Expand Down

0 comments on commit c8872fc

Please sign in to comment.