From 53f00bee122105c0e17027b70419f2b8a0ce313c Mon Sep 17 00:00:00 2001 From: Vasu Bhog Date: Sat, 10 Oct 2020 00:10:33 -0500 Subject: [PATCH] Fix connection when changing kernel from Kusto to SQL (#12881) * Fix Kusto to SQL kernel connection change * Updated Fix - removes kernel alias mapping while ensuring multi kusto notebooks work properly * Fix tests --- .../notebook/browser/models/notebookModel.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sql/workbench/services/notebook/browser/models/notebookModel.ts b/src/sql/workbench/services/notebook/browser/models/notebookModel.ts index c20a52a1d0..7da33cb3b9 100644 --- a/src/sql/workbench/services/notebook/browser/models/notebookModel.ts +++ b/src/sql/workbench/services/notebook/browser/models/notebookModel.ts @@ -845,6 +845,15 @@ export class NotebookModel extends Disposable implements INotebookModel { if (newConnection) { if (newConnection.serverCapabilities?.notebookKernelAlias) { this._currentKernelAlias = newConnection.serverCapabilities.notebookKernelAlias; + // Removes SQL kernel to Kernel Alias Connection Provider map + let sqlConnectionProvider = this._kernelDisplayNameToConnectionProviderIds.get('SQL'); + if (sqlConnectionProvider) { + let index = sqlConnectionProvider.indexOf(newConnection.serverCapabilities.notebookKernelAlias.toUpperCase()); + if (index > -1) { + sqlConnectionProvider.splice(index, 1); + } + this._kernelDisplayNameToConnectionProviderIds.set('SQL', sqlConnectionProvider); + } this._kernelDisplayNameToConnectionProviderIds.set(newConnection.serverCapabilities.notebookKernelAlias, [newConnection.providerName]); } this._activeConnection = newConnection; @@ -971,6 +980,9 @@ export class NotebookModel extends Disposable implements INotebookModel { private async loadActiveContexts(kernelChangedArgs: nb.IKernelChangedArgs): Promise { if (kernelChangedArgs && kernelChangedArgs.newValue && kernelChangedArgs.newValue.name) { let kernelDisplayName = this.getDisplayNameFromSpecName(kernelChangedArgs.newValue); + if (this.context?.serverCapabilities?.notebookKernelAlias && this.selectedKernelDisplayName === this.context?.serverCapabilities?.notebookKernelAlias) { + kernelDisplayName = this.context.serverCapabilities?.notebookKernelAlias; + } let context; if (this._activeConnection) { context = NotebookContexts.getContextForKernel(this._activeConnection, this.getApplicableConnectionProviderIds(kernelDisplayName));