Fix issues due to missing notebook values (specs and cells) (#4008)

- Fix #3844
    - Fix #3955
    - Specs can be null on early load of Jupyter kernels
    - Cells were missing in some reference test .ipynb files. We should be resilient to malformed files if possible.
This commit is contained in:
Kevin Cunnane
2019-02-11 17:17:56 -08:00
committed by GitHub
parent 62404721ed
commit 67f9a7f5e4
2 changed files with 11 additions and 5 deletions

View File

@@ -546,8 +546,12 @@ export class NotebookModel extends Disposable implements INotebookModel {
return kernel;
}
private getDisplayNameFromSpecName(kernelid: string): string {
let newKernel = this.notebookManager.sessionManager.specs.kernels.find(kernel => kernel.name === kernelid);
private getDisplayNameFromSpecName(kernel: nb.IKernel): string {
let specs = this.notebookManager.sessionManager.specs;
if (!specs || !specs.kernels) {
return kernel.name;
}
let newKernel = this.notebookManager.sessionManager.specs.kernels.find(kernel => kernel.name === kernel.name);
let newKernelDisplayName;
if (newKernel) {
newKernelDisplayName = newKernel.display_name;
@@ -586,7 +590,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
private async loadActiveContexts(kernelChangedArgs: nb.IKernelChangedArgs): Promise<void> {
if (kernelChangedArgs && kernelChangedArgs.newValue && kernelChangedArgs.newValue.name) {
let kernelDisplayName = this.getDisplayNameFromSpecName(kernelChangedArgs.newValue.name);
let kernelDisplayName = this.getDisplayNameFromSpecName(kernelChangedArgs.newValue);
this._activeContexts = await NotebookContexts.getContextsForKernel(this.notebookOptions.connectionService, this.getApplicableConnectionProviderIds(kernelDisplayName), kernelChangedArgs, this.connectionProfile);
this._contextsChangedEmitter.fire();
if (this.contexts.defaultConnection !== undefined && this.contexts.defaultConnection.serverName !== undefined) {

View File

@@ -71,8 +71,10 @@ namespace v4 {
nbformat_minor: contents.nbformat_minor
};
for (let cell of contents.cells) {
notebook.cells.push(readCell(cell));
if (contents.cells) {
for (let cell of contents.cells) {
notebook.cells.push(readCell(cell));
}
}
return notebook;