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

Ensure that we get the text as text (not json) #1286

Merged
merged 1 commit into from
Dec 15, 2024

Conversation

mwouts
Copy link
Owner

@mwouts mwouts commented Dec 8, 2024

When jupyter-collaboration is installed, the format argument in

            text = self.super.get(
                alt_path, content=True, type="file", format=format
            )["content"]

equals json, and because of that we get a base64 encoding of the notebook inputs instead of the notebook inputs themselves.

That is a very serious issue, as the notebook appears with a single cell that is unreadable. If the user saves or autosaves the notebook then the notebook will be corrupted on disk. In that case, the inputs can be recovered (but not the outputs) with:

text = """IyAtLS0K...""" # copy the corrupted cell
print(base64.b64decode("".join(text.splitlines())).decode('utf8'))  # this will recover the .py file

This PR addresses this problem by setting format="text", instead of inherited it from the parent call.

Fixes #1124
Fixes jupyterlab/jupyter-collaboration#214

Copy link

github-actions bot commented Dec 8, 2024

Thank you for making this pull request.

Did you know? You can try it on Binder: Binder:lab or Binder:notebook.

Also, the version of Jupytext developed in this PR can be installed with pip:

HATCH_BUILD_HOOKS_ENABLE=true pip install git+https://github.com/mwouts/jupytext.git@fix_notebook_corruption_with_jupyter_collaboration

(this requires nodejs, see more at Developing Jupytext)

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.03%. Comparing base (8dccab4) to head (3dfd38b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1286   +/-   ##
=======================================
  Coverage   97.03%   97.03%           
=======================================
  Files          29       29           
  Lines        4481     4481           
=======================================
  Hits         4348     4348           
  Misses        133      133           
Flag Coverage Δ
external 75.01% <ø> (ø)
functional 88.53% <ø> (ø)
integration 77.23% <ø> (ø)
unit 66.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mwouts
Copy link
Owner Author

mwouts commented Dec 15, 2024

please update playwright snapshots

@mwouts mwouts force-pushed the fix_notebook_corruption_with_jupyter_collaboration branch from af4a8eb to 3dfd38b Compare December 15, 2024 16:04
@mwouts mwouts merged commit f2e1b9d into main Dec 15, 2024
31 checks passed
@mwouts mwouts deleted the fix_notebook_corruption_with_jupyter_collaboration branch December 15, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatible with Jupytext plugin (notebook corruption) Using real time collaboration with Jupytext
1 participant