diff --git a/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts b/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts index a6dffb384c..91eb70ccd7 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts @@ -417,6 +417,10 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu } } + get modelResolved(): Promise { + return this._modelResolved.promise; + } + private hookDirtyListener(dirtyEvent: Event, listener: (e: any) => void): void { let disposable = dirtyEvent(listener); if (this._dirtyListener) { diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts index 56f7cc61d3..9d8de09be7 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -223,6 +223,9 @@ CommandsRegistry.registerCommand({ for (let editor of editors) { if (editor instanceof NotebookInput) { + // Wait for NotebookInput.resolve() to be called to ensure the _model field in NotebookInput + // is not undefined when trying to get the notebookModel. + await editor.modelResolved; let model: INotebookModel = editor.notebookModel; if (model?.providerId === JUPYTER_PROVIDER_ID) { let jupyterNotebookManager: IExecuteManager = model.executeManagers.find(x => x.providerId === JUPYTER_PROVIDER_ID);