Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/notebooks/deepnote/deepnoteDataConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class DeepnoteDataConverter {

private createFallbackBlock(cell: NotebookCellData, index: number): DeepnoteBlock {
const meta = cell.metadata as Record<string, unknown> | undefined;
const preservedId = (meta?.id ?? meta?.__deepnoteBlockId ?? meta?.deepnoteBlockId) as string | undefined;
const preservedId = (meta?.__deepnoteBlockId ?? meta?.id ?? meta?.deepnoteBlockId) as string | undefined;
const preservedSortingKey = (meta?.sortingKey ?? meta?.deepnoteSortingKey) as string | undefined;
const preservedBlockGroup = meta?.blockGroup as string | undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/notebooks/deepnote/deepnoteFileChangeWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export class DeepnoteFileChangeWatcher implements IExtensionSyncActivationServic
}

private getBlockIdFromMetadata(metadata: Record<string, unknown> | undefined): string | undefined {
return (metadata?.id ?? metadata?.__deepnoteBlockId) as string | undefined;
return (metadata?.__deepnoteBlockId ?? metadata?.id) as string | undefined;
}

private handleFileChange(uri: Uri): void {
Expand Down
28 changes: 28 additions & 0 deletions src/notebooks/deepnote/deepnoteFileChangeWatcher.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,34 @@ project:
execOnDidCreate.dispose();
});

test('should not apply updates when cells have no block IDs and no fallback', async () => {
const snapshotUri = Uri.file('/workspace/snapshots/my-project_project-1_latest.snapshot.deepnote');
const notebook = createMockNotebook({
uri: Uri.file('/workspace/test.deepnote'),
cells: [
{
metadata: {},
outputs: [],
kind: NotebookCellKind.Code,
document: { getText: () => 'print("hello")' }
}
]
});

when(mockedVSCodeNamespaces.workspace.notebookDocuments).thenReturn([notebook]);

snapshotOnDidChange.fire(snapshotUri);

await waitFor(() => readSnapshotCallCount >= 1);

assert.isAtLeast(readSnapshotCallCount, 1, 'readSnapshot should be called');
assert.strictEqual(
snapshotApplyEditCount,
0,
'applyEdit should NOT be called when no block IDs can be resolved'
);
});

test('should fall back to replaceCells when no kernel is active', async () => {
const fbDisposables: IDisposableRegistry = [];
const fbOnDidChange = new EventEmitter<Uri>();
Expand Down
2 changes: 1 addition & 1 deletion src/platform/deepnote/pocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function createBlockFromPocket(cell: NotebookCellData, index: number): De
const metadata = cell.metadata ? { ...cell.metadata } : undefined;
// Get id from top-level metadata before cleaning it up
// Check both 'id' and backup '__deepnoteBlockId' in case VS Code modifies 'id'
const cellId = (metadata?.id as string | undefined) || (metadata?.__deepnoteBlockId as string | undefined);
const cellId = (metadata?.__deepnoteBlockId as string | undefined) || (metadata?.id as string | undefined);

logger.debug(
`[Pocket] createBlockFromPocket index=${index}: cell.metadata.id=${metadata?.id}, __deepnoteBlockId=${metadata?.__deepnoteBlockId}, using cellId=${cellId}, metadata keys=${
Expand Down
Loading