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

diff doesn't work for notebook under lfs #1055

Open
ebw44 opened this issue Nov 9, 2021 · 8 comments
Open

diff doesn't work for notebook under lfs #1055

ebw44 opened this issue Nov 9, 2021 · 8 comments

Comments

@ebw44
Copy link

ebw44 commented Nov 9, 2021

Description

The diff of a notebook track under lfs doesn't work. I get the message Error Loading Notebook Diff: Internal Server Error in the new tab and the error below in the console:

[E 2021-11-09 14:06:23.072 ServerApp.jupyterlab_git] Error computing notebook diff.
    Traceback (most recent call last):
      File "C:\Users\username\mambaforge\lib\site-packages\nbformat\reader.py", line 14, in parse_json
        nb_dict = json.loads(s, **kwargs)
      File "C:\Users\username\mambaforge\lib\json\__init__.py", line 346, in loads
        return _default_decoder.decode(s)
      File "C:\Users\username\mambaforge\lib\json\decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "C:\Users\username\mambaforge\lib\json\decoder.py", line 355, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "C:\Users\username\mambaforge\lib\site-packages\jupyterlab_git\handlers.py", line 709, in post
        content = await self.git.get_nbdiff(
      File "C:\Users\username\mambaforge\lib\site-packages\jupyterlab_git\git.py", line 361, in get_nbdiff
        prev_nb = await current_loop.run_in_executor(None, read_notebook, prev_content)
      File "C:\Users\username\mambaforge\lib\concurrent\futures\thread.py", line 52, in run
        result = self.fn(*self.args, **self.kwargs)
      File "C:\Users\username\mambaforge\lib\site-packages\jupyterlab_git\git.py", line 352, in read_notebook
        return nbformat.reads(content, as_version=4)
      File "C:\Users\username\mambaforge\lib\site-packages\nbformat\__init__.py", line 73, in reads
        nb = reader.reads(s, **kwargs)
      File "C:\Users\username\mambaforge\lib\site-packages\nbformat\reader.py", line 58, in reads
        nb_dict = parse_json(s, **kwargs)
      File "C:\Users\username\mambaforge\lib\site-packages\nbformat\reader.py", line 17, in parse_json
        raise NotJSONError(("Notebook does not appear to be JSON: %r" % s)[:77] + "...") from e
    nbformat.reader.NotJSONError: Notebook does not appear to be JSON: 'version https://git-lfs.github.com/spec...
[W 2021-11-09 14:06:23.073 ServerApp] Internal Server Error
[E 2021-11-09 14:06:23.090 ServerApp] {
      "Host": "localhost:8888",
      "Connection": "keep-alive",
      "Content-Length": "4093218",
      "Sec-Ch-Ua": "\"Google Chrome\";v=\"95\", \"Chromium\";v=\"95\", \";Not A Brand\";v=\"99\"",
      "Authorization": "token d22641373b435360d2896c5c143a8049569b491f0e9aee58",
      "X-Xsrftoken": "2|9b86ad76|ea46566fea3cecccfa1f550e20597ee5|1634077816",
      "Sec-Ch-Ua-Mobile": "?0",
      "Content-Type": "text/plain;charset=UTF-8",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
      "Sec-Ch-Ua-Platform": "\"Windows\"",
      "Accept": "*/*",
      "Origin": "http://localhost:8888",
      "Sec-Fetch-Site": "same-origin",
      "Sec-Fetch-Mode": "cors",
      "Sec-Fetch-Dest": "empty",
      "Referer": "http://localhost:8888/lab",
      "Accept-Encoding": "gzip, deflate, br",
      "Accept-Language": "en-US,en;q=0.9,fr;q=0.8",
      "Cookie": "_xsrf=2|9b86ad76|ea46566fea3cecccfa1f550e20597ee5|1634077816; username-localhost-8889=\"2|1:0|10:1634864179|23:username-localhost-8889|44:N2M3ZWNhNDMxYmNlNGM0NGEzZmE5MTYwMGZlMmQzNmY=|253c54a46b14ca8372b4e2cae96bea7624777f549ab0109ab8e2084bd8d13b7d\"; username-localhost-8888=\"2|1:0|10:1636419982|23:username-localhost-8888|44:N2MwYzYxNTAwNDYwNDg5N2E1MjA2OGNhOGRkNzRlNzU=|f698be6a8b2483595ca8c79e87bb5253f575f62090d974df879edf9dc06b496e\""
    }

I had the same issue with nbdime#608 and it was solved by doing some changes in the .git/config and .gitattributes files

Context

  • Python package version:
    jupyterlab-git 0.33.0 pyhd8ed1ab_0 conda-forge
  • Extension version:
    @jupyterlab/git v0.33.0 enabled ok (python, jupyterlab-git)
  • Git version:
    git version 2.33.1.windows.1
    git-lfs/3.0.1 (GitHub; windows amd64; go 1.17.1)
  • Operating System and its version:
    Windows 10
@ebw44 ebw44 added the bug label Nov 9, 2021
@welcome
Copy link

welcome bot commented Nov 9, 2021

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@fcollonval
Copy link
Member

Hey @ebw44 could you provide more details:

  • Were you using the configuration mentioned in the nbdime issue (displayed below for interested readers)?
  • What kind of diff did you try to display? Diff on the history panel, diff for staged changes, diff for unstaged changes?

.gitattributes

*.ipynb filter=lfs diff=jupyternotebook

and .git/config

[diff "jupyternotebook"]
	command = git-nbdiffdriver webdiff --ip 127.0.0.1
	textconv = cat

@ebw44
Copy link
Author

ebw44 commented Nov 9, 2021

Hey @fcollonval here are more details:

  • I was using the configuration below:
    .gitattributes
    *.ipynb filter=lfs diff=jupyternotebook
    and .git/config
[diff "jupyternotebook"]
	command = git-nbdiffdriver webdiff --ip 127.0.0.1
	textconv = cat
  • I just tried the 3 diff mentioned (history, staged changes and unstaged changes) and neither work for an ipynb

@fcollonval
Copy link
Member

Thanks for the additional information @ebw44

I have for now no clue what so ever to deal with that. So happy to get some help.

@ebw44
Copy link
Author

ebw44 commented Nov 10, 2021

From my search to find solutions for nbdime and vscode notebook diff, one thing that came up was to add the lines below to .git/config.

[diff "lfs"]
	textconv = cat

also to see a revision of the Validation.ipynb file I need to run:
git show HEAD:Validation.ipynb | git lfs smudge > Validation_head.ipynb
the smudge pipe is required because
git show HEAD:Validation.ipynb > Validation_head.ipynb
result in Validation_head.ipynb containing only a lfs pointer not the actual file.

@fcollonval
Copy link
Member

Could provide here the result of git config --list? At minimum anything that starts with filter. or contains lfs.

I think nbdime is able to deal with it because it supports git filters that this extension does not (Xref #529).

@ebw44
Copy link
Author

ebw44 commented Nov 11, 2021

Here is the result of git config --list

diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=true
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=main
core.autocrlf=true
core.editor="C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd" --wait
difftool.sourcetree.cmd='' "$LOCAL" "$REMOTE"
mergetool.sourcetree.cmd=''
mergetool.sourcetree.trustexitcode=true
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
pull.rebase=true
rebase.autostash=true
init.defaultbranch=main
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.pushurl=https://
branch.main.remote=origin
branch.main.merge=refs/heads/main
lfs.https://dev.azure.com/
lfs.https://dev.azure.com/
diff.lfs.textconv=cat
lfs.repositoryformatversion=0
diff.jupyternotebook.command=git-nbdiffdriver webdiff --ip 127.0.0.1
diff.jupyternotebook.textconv=cat

@perrette
Copy link

perrette commented Sep 24, 2024

Specifying the .gitattributes and .git/config shown above by @fcollonval and @ebw44 worked for me (diff in json format, but that's fine). Thanks.
EDIT: diff by clicking on the M in the Source control tree view (side panel).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants