Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsaved Notebook data is lost on exit #1746

Closed
dimitry-ishenko opened this issue May 8, 2020 · 17 comments
Closed

Unsaved Notebook data is lost on exit #1746

dimitry-ishenko opened this issue May 8, 2020 · 17 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@dimitry-ishenko
Copy link

Bug: Notebook Editor, Interactive Window, Editor cells

Steps to cause the bug to occur

  1. Launch VSCode.
  2. Create new blank Notebook (Ctrl+Shift+P then enter Python: Create Blank New Jupyter Notebook)
  3. Modify the notebook (eg, enter print("Hello abyss!") in the cell and press Ctrl+Enter)
  4. Close VSCode.
  5. Re-launch VSCode.
  6. Witness your work gone into the abyss.
  7. Optional: Smash computer screen with heavy object.

Actual behavior

VSCode blissfully discards any unsaved changes.

Expected behavior

Either (a) an "Are you sure?"-type confirmation dialog is shown on exit; or (b) the file is restored, when VSCode is relaunched, which is what's done with other file types.

Your Jupyter and/or Python environment

Please provide as much info as you readily know

  • Jupyter server running: N/A
  • Extension version: v2020.4.76186
  • VS Code version: 1.45
  • Setting python.jediEnabled: false
  • Python and/or Anaconda version: python 3.8.2 (no Anaconda)
  • OS: Ubuntu 20.04 LTS
  • Virtual environment: N/A

Developer Tools Console Output

Nah... that ain't me

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

@dimitry-ishenko
Copy link
Author

Looking at some of the other issues, I see an overarching issue in that the Notebooks are not treated as first class citizen in VSCode.

For example, when I open a Notebook I see this funny thing play out where VSCode will open it as a plain text file first, then quickly hide it and reopen as a Notebook. 🥴 That doesn't always work and I end up with a blank file. If I close and reopen, second time is usually a charm. (Should probably file a separate issue for that.)

@claudiaregio
Copy link
Contributor

Thanks for the feedback @dimitry-ishenko , we will take a look!

@rchiodo rchiodo self-assigned this May 18, 2020
@dimitry-ishenko
Copy link
Author

Came here to complain as I've just lost another notebook and see @rchiodo is working on it. Thank you!

@joyceerhl
Copy link
Contributor

Validated.

@tbenst
Copy link

tbenst commented Jul 10, 2020

Note that this problem is especially bad if VSCode crashes or is closed accidentally (i.e. I errantly typed ctrl-w to delete a word from terminal habit but closed the tab and lost all my work. 🤦). Classic Jupyter as served in browser lets you reload the webpage and presents you with your unsaved changes. Likewise, VScode does something similiar with .py files. Please adopt the behavior from .py files:

  1. add the x or o icon on the notebook viewer tab
  2. prompt to save if closing
  3. restore unsaved on crash

Thanks so much for this excellent extension :)

@dimitry-ishenko
Copy link
Author

dimitry-ishenko commented Jul 10, 2020

@tbenst If I understand it correctly (and @rchiodo can correct me if I am wrong) this and a host of other similar issues all depend on issue #1326. Notebook support was added through use of some dark voodoo and so they are not treated as first-class citizen in vscode. Until that changes, issues like this will keep popping up.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 10, 2020

Yes @dimitry-ishenko you're correct. We're working with VS code to make notebooks a first class citizen of VS code. That work was started here:
https://github.com/microsoft/vscode-python/issues/10496

However the problem with unsaved files not reopening should be fixed already. You do need to reactivate the python extension for it to work. We do have our own 'hot-save' mechanism, which is what VS code calls saving a backup copy of your work while you type.

@dimitry-ishenko
Copy link
Author

@rchiodo thank you sir, now I have something to look forward to 😄

@tbenst actually @rchiodo is correct this has been fixed. What I usually do is keep an empty python tab open to force the python extension reactivation, when I re-launch vscode:

Peek 2020-07-10 14-09

You can even create an empty python tab after you've closed and re-launched vscode and bring your notebook back from the dead:

Peek 2020-07-10 14-15

@allefeld
Copy link

allefeld commented Jul 12, 2020

Unfortunately, this still seems to happen.

I had a notebook with unsaved changes and exited vscode. There was no warning about unsaved changes.

When I restarted vscode with the same workspace, the notebook was not automatically opened. I opened it manually, which must have triggered "reactivation", because then a second copy of the notebook was opened. Maybe that automatically opened second copy contained my unsaved changes – I don't know, because I clicked it away since it seemed redundant.

I cannot find any trace of my unsaved changes in either of .vscode, ~/.vscode , or ~/config/Code. Is there another place I can look for them?

It would be great if one would be warned about unsaved changes upon exiting, or if files.autoSave applied to notebooks.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 13, 2020

@allefeld on a windows machine the 'hot exit' files are stored here:

C:\Users\rchiodo.REDMOND\AppData\Roaming\Code\User\globalStorage\ms-python.python

They should have a file with a hash of the original file path.

The root cause of the problem is the activation of the python extension that's required for us to reopen files.

@allefeld
Copy link

@rchiodo, I think that's ~/config/Code/User/globalStorage/ms-python.python on Linux, thanks. Unfortunately there was nothing there.

Will this problem be solved with the undergoing redesign of custom editors in VS Code? At least a warning about unsaved changes would be extremely useful.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 13, 2020

Yes the redesign to use the VS custom editors will eliminate this entirely because we'll suddenly be known as an editor by VS code. They'll handle the hot exit/save/save as for us.

@allefeld
Copy link

Great, thanks!

@tbenst
Copy link

tbenst commented Jul 13, 2020

@allefeld when I switch Jupyter backend URI, the extension prompts me to restart VScode. I’ve found that it works if I do NOT restart VScode, but that upon restarting I cannot use the backend I entered.

Perhaps this is why unsaved data is still lost for me?

@allefeld
Copy link

@tbenst, I'm not a developer, just a user like you.

@IanMatthewHuff
Copy link
Member

@DavidKutu and I both validated this. Validated.

@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 13, 2020
@DonJayamanne DonJayamanne added the bug Issue identified by VS Code Team member as probable bug label Nov 13, 2020
@msveshnikov
Copy link

Just for everyone information - I was able to find my unsaved notebook with 2 days of work in "C:\Users\user\Local Settings\Temp"

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

9 participants