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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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 (a6615c6) to head (af4a8eb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1286      +/-   ##
==========================================
- Coverage   97.05%   97.03%   -0.03%     
==========================================
  Files          29       29              
  Lines        4479     4479              
==========================================
- Hits         4347     4346       -1     
- Misses        132      133       +1     

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

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