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

order of json dicts not preserved in jupyter notebooks save files #129435

Closed
JoranDox opened this issue Jul 26, 2021 · 10 comments
Closed

order of json dicts not preserved in jupyter notebooks save files #129435

JoranDox opened this issue Jul 26, 2021 · 10 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug notebook-ipynb

Comments

@JoranDox
Copy link

Environment data

  • VS Code version: Version: 1.58.2
    Commit: c3f1263
    Date: 2021-07-14T22:30:16.440Z
    Electron: 12.0.13
    Chrome: 89.0.4389.128
    Node.js: 14.16.0
    V8: 8.9.255.25-electron.0
    OS: Linux x64 5.4.0-80-generic snap
  • Jupyter Extension version (available under the Extensions sidebar): v2021.8.1054968649
  • Type of virtual environment used N/A
  • Jupyter server running: Local

Expected behaviour

Make a small change, see only the change in git

Actual behaviour

Make a small change, the whole file is changed according to git (order of json dict entries is suddenly changed)

Steps to reproduce:

  1. change something to a notebook in git
  2. see this for every cell in the notebook:
  3. image

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

XXX

@JoranDox
Copy link
Author

note: if anyone else has this issue, these lines give a workaround:

import sys
import json

fname = sys.argv[1]
with open(fname) as f:
    s = f.read()
    j = json.loads(s)


with open(fname, "w") as f:
    f.write(json.dumps(j, sort_keys=True, indent=1))

use it like this (maybe make a backup first to be sure):
python sortnotebook.py notebookthatsruined.ipynb

@joyceerhl
Copy link
Collaborator

@DonJayamanne IIRC we used to sort the keys in the notebook JSON to avoid creating noise like this (at least for the webview implementation). We should probably continue to do that moving forward

@rebornix rebornix transferred this issue from microsoft/vscode-jupyter Jul 26, 2021
@vscodebot
Copy link

vscodebot bot commented Jul 26, 2021

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@DonJayamanne
Copy link
Contributor

Oh yes, looks like we aren't doing that.

@roblourens
Copy link
Member

Is there code for this that got lost in moving to builtin? I thought I remembered that but didn't see code for it, if you point me to it I can port it over

@DonJayamanne
Copy link
Contributor

@roblourens
Copy link
Member

It looks like that function isn't called anywhere from vscode-jupyter though

@DonJayamanne
Copy link
Contributor

sn't called anywhere from vscode-jupyter though

Yes, as Joyce mentioned we're not using it. This was used in the old custom editor.

@roblourens roblourens modified the milestones: July 2021, August 2021 Jul 27, 2021
@roblourens roblourens added the bug Issue identified by VS Code Team member as probable bug label Jul 27, 2021
@rebornix rebornix removed their assignment Jul 28, 2021
@rebornix rebornix removed the notebook label Oct 21, 2021
@rebornix rebornix removed their assignment Oct 21, 2021
@joyceerhl joyceerhl removed their assignment Oct 26, 2021
@roblourens roblourens removed this from the October 2021 milestone Oct 27, 2021
@roblourens
Copy link
Member

@DonJayamanne already implemented this, thanks

@roblourens roblourens removed this from the November 2021 milestone Nov 2, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 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 notebook-ipynb
Projects
None yet
Development

No branches or pull requests

7 participants
@roblourens @rebornix @DonJayamanne @JoranDox @tanhakabir @joyceerhl and others