Vscode-jupyter: Code getting shuffled -- causing errors

Created on 2 Oct 2020  ·  7Comments  ·  Source: microsoft/vscode-jupyter

Bug: Notebook Editor, Interactive Window, Editor cells

Issue

Not sure how to get this to reproduce but got the same complaint from another customer two days ago.
Was using the notebook and running and editing code and all of a sudden I got an error for code that is not in my cell.
The cell appears to have somehow laced code together that led to an error.

The only solution is to copy and paste the code into a new cell and delete the old.

Actual behavior

image

Your Jupyter and/or Python environment

_Please provide as much info as you readily know_

  • Jupyter server running: Local
  • Extension version: v2020.10.111333
  • VS Code version: 1.49.2
  • Setting python.languageServer: Pylance
  • Python and/or Anaconda version: 3.7.6
  • OS: Windows: x64 10.0.19042
  • Virtual environment: conda

Python Output

Info 2020-10-01 21:53:08: Executing cell NotebookImport#0
Info 2020-10-01 21:53:08: Submitting code for 3d9bab26-629b-4fb7-bf33-f50ce597a9e7
Info 2020-10-01 21:53:08: Kernel switching to busy
Info 2020-10-01 21:53:08: Kernel switching to idle
Info 2020-10-01 21:53:08: Kernel switching to busy
Info 2020-10-01 21:53:09: Kernel switching to idle
Info 2020-10-01 21:53:09: Finished execution for NotebookImport#0
Info 2020-10-01 21:53:09: Finished executing cell NotebookImport#0
Info 2020-10-01 21:53:12: Executing cell NotebookImport#1
Info 2020-10-01 21:53:12: Submitting code for 3d9bab26-629b-4fb7-bf33-f50ce597a9e7
Info 2020-10-01 21:53:12: Kernel switching to busy
Info 2020-10-01 21:53:13: Kernel switching to idle
Info 2020-10-01 21:53:13: Finished execution for NotebookImport#1
Info 2020-10-01 21:53:13: Finished executing cell NotebookImport#1
Info 2020-10-01 21:53:14: Executing cell NotebookImport#2
Info 2020-10-01 21:53:14: Submitting code for 3d9bab26-629b-4fb7-bf33-f50ce597a9e7
Info 2020-10-01 21:53:14: Kernel switching to busy
Info 2020-10-01 21:53:14: Finished execution for NotebookImport#2
Info 2020-10-01 21:53:14: Finished executing cell NotebookImport#2
Info 2020-10-01 21:53:14: Kernel switching to idle

Microsoft Data Science for VS Code Engineering Team: @rchiodo, @IanMatthewHuff, @DavidKutu, @DonJayamanne, @greazer, @joyceerhl

bug

All 7 comments

This sounds similar to issues we've had in the past where the cell content and the editor content are out of sync

Yup, i think we identified this was due to undo/redo.

This issue will likely be addressed once VS Code adds native support for editing notebooks. Please see https://github.com/microsoft/vscode/issues/91987.

But if anybody experiences this with the current notebook support, please try to find a consistent repro. This has been very hard to diagnose.

I encountered this today, i had a line like

Sys.Stdout = open(xx,xx) and every time i try to edit and save, this line would be shuffled in between the import statements above it.

However, i wouldn’t be able to see this shuffled data until i reloaded the notebook.

I started with a clean install and this hasn’t occurred yet.

Latest insider build here.

[edit] happened again, edited the following line:

“For do, sqldf in zip(dfs, sheets)”

To

“For do, sqldf in zip(dfs, sheetstwo)”

And tried to run the code, I got errors so i reloaded the script and the same line has changed to

“For do, sqldf in zip(dfs, sheetssheetstwo)”

Jupyter 2020.1.192013122
Python 2020.11.371526539.

The workaround for this as identified by @giammi56 is to copy the contents of the cell to the clipboard, delete the cell, create a new cell in the same spot and paste the old cell.

The root cause is the edit operations from the UI are not propagating to our backend. Recreating the cell causes the backend to reread the entire contents.

Since we can't repro this very well, we should at least find a way for users to work around the problem. Ultimately, VS Code's native notebooks should address this, but it's ugly. The proposal is to copy the contents of the cell to run when user executes the cell. In addition we could update all cell contents on save.

The way I think this could work is:

  • On execute post a message to the UI to return the contents of the cell
  • Wait for response. Update model with new contents, then execute.
  • On save, post a message to the UI to return all cells
  • Wait for response, Update model with new contents, save the model
Was this page helpful?
0 / 5 - 0 ratings