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

Can't save notebooks when toc2 extension is enabled #762

Closed
DavidJBianco opened this issue Oct 12, 2016 · 12 comments
Closed

Can't save notebooks when toc2 extension is enabled #762

DavidJBianco opened this issue Oct 12, 2016 · 12 comments

Comments

@DavidJBianco
Copy link

I've noticed that when I have the toc2 extension enabled, I can load notebooks just fine, but pressing the "Save" button or using the save command under the File menu doesn't work. Looking at the jupyter server output without toc2 enabled, I get a log message that confirms that a save operation took place. However, with the toc2, no such message. And the notebook knows it hasn't been saved, since I get the message about unsaved changes when I try to navigate away.

Has anyone else seen this?

@DavidJBianco
Copy link
Author

I should mention that this occurs whenever I have toc2 enabled, even if I have none of the other extensions here enabled. I do have the IPython widgets loaded, but nothing else.

@DavidJBianco
Copy link
Author

I also found this in the JavaScript console, which seems to be the culprit.

pcr_analysis_hunt__sqrrl_query_

@jfbercher
Copy link
Member

It seems that there is no toc section in your notebook's metadata, though it should have be created when loading the extension via main.js. Can you confirm that by looking at edit menu / Edit notebook metadata?

@DavidJBianco
Copy link
Author

DavidJBianco commented Oct 12, 2016

Yeah, I don't see a toc section. Here's the whole thing:

{
  "kernelspec": {
    "name": "python2",
    "display_name": "Python 2",
    "language": "python"
  },
  "widgets": {
    "state": {
      "98936d8870f84cffa288e5ced44a8b24": {
        "views": [
          {
            "cell_index": 20
          }
        ]
      }
    },
    "version": "1.2.0"
  },
  "hide_input": false,
  "language_info": {
    "mimetype": "text/x-python",
    "nbconvert_exporter": "python",
    "name": "python",
    "pygments_lexer": "ipython2",
    "version": "2.7.11",
    "file_extension": ".py",
    "codemirror_mode": {
      "version": 2,
      "name": "ipython"
    }
  },
  "celltoolbar": "Initialisation Cell"
}

@jfbercher
Copy link
Member

jfbercher commented Oct 12, 2016

Ok; It seems that config load fails somewhere.

  • Are you able to find something related to config in the js console?
  • Can you look in your notebook.json located in the nbconfig subdirectory of your config directory (see jupyter --path to find it, or ~/.jupyter under linux) and see if there is a toc2 section. if not, open a tab at localhost:8888/nbextensions in your browser, select toc2 and try to modify some parameter. Report here if it changes something (unfortunately I can't check myself ; I haven't a jupyter at hand)

@DavidJBianco
Copy link
Author

I didn't see anything about config in the console, though you were correct about there not being in "toc2" section in the notebook.json. I modified a toc2 setting, though, and one appeared. After restarting the notebook server (just in case) it seems like it's now working, at least for notebooks that I never loaded with the toc2 extension before. The ones I tried to use with toc2, though, still have the same issue. I'm assuming it's something in the metadata, so I'll continue to look at that.

@jfbercher
Copy link
Member

I cannot reproduce (despite my efforts). Browser ? jupyter version?
In toc2.js line 92-94 populates the metadata with the actual dims of the navigation menu. The nav_menu should have been created, if non existing, in line 89. What happens here is that the toc section in the notebook's metadata doesn't exist, though it is created in main.js, lines 44-62 and lines 107-109. Though it is still possible that table_of_contents() is called before the config full load; it seems that the config is never loaded or at least that the notebook's metadata is not updated/written here. I dont't see why.
It should be possible to strengthen l89-95 whith the creation of toc section, then nav_menu if both do not exist; but I would prefer to understand what happens at root.

The ones I tried to use with toc2, though, still have the same issue. I'm assuming it's something in the metadata,

I don't see what can happen. You can try to initialize the metadata yourself by adding
"toc": {
"nav_menu": {}
},
in the notebook's metadata.

@DavidJBianco
Copy link
Author

I'm using Jupyter 4.2.0 and Chrome 53.0.2785.143 (64-bit). I think the
only slightly odd thing about my install (maybe) is that I initially
enabled installed things with jupyter contrib nbextension install --user
but it ended up that I had to use --system instead, so I reran the
command without first uninstalling it. Otherwise I just followed the
instructions in the github README.

On Wed, 12 Oct 2016 at 12:27 jfbercher [email protected] wrote:

I cannot reproduce (despite my efforts). Browser ? jupyter version?
In toc2.js line 92-94
https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js#L92-L94
populates the metadata with the actual dims of the navigation menu. The
nav_menu should have been created, if non existing, in line 89
https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js#L89.
What happens here is that the toc section in the notebook's metadata
doesn't exist, though it is created in main.js, lines 44-62
https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js#L44-L62
and lines 107-109
https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js#L107-L109.
Though it is still possible that table_of_contents() is called before the
config full load; it seems that the config is never loaded or at least that
the notebook's metadata is not updated/written here. I dont't see why.
It should be possible to strengthen l89-95
https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js#L89-L95
whith the creation of toc section, then nav_menu if both do not exist; but
I would prefer to understand what happens at root.

The ones I tried to use with toc2, though, still have the same issue. I'm
assuming it's something in the metadata,

I don't see what can happen. You can try to initialize the metadata
yourself by adding
"toc": {
"nav_menu": {}
},
in the notebook's metadata.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#762 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AIt4fa3T9j8znTJBMQBcP0HITbZX1LZZks5qzQphgaJpZM4KUvb2
.

@jcb91
Copy link
Member

jcb91 commented Oct 13, 2016

@DavidJBianco I don't think your potential double-install would cause this problem (and may well cause none at all), but in any case you ought still to be able to fix it for future peace-of-mind by running

jupyter contrib nbextension uninstall --user
jupyter contrib nbextension install --system

Running the system install command again shouldn't cause any problems, so it's worth rerunning after uninstalling the --user version just to make sure nothing's missing.

It might help reproducing the error if you could supply a sample notebook which causes the behaviour for you?

@jcb91
Copy link
Member

jcb91 commented Nov 15, 2016

As mentioned in jupyter/notebook#1882 (comment), this is probably caused by a race condition between the nbextension aditing metadata, and the notebook load editing it. If the nbextension makes its edits before the notebook finishes loading (liable to happen with large notebooks and/or high latency connections), then the notebook load event eventually overwrites the already-made nbextension edits. Hopefully we can get the relevant fix merged into this repo soon.

@jfbercher
Copy link
Member

Yes @jcb91 I will upload the fix shortly.
This will also include the (yet partial) answer to #791

jcb91 added a commit that referenced this issue Nov 24, 2016
[toc2] Highlight toc headings for sections with selected/edited/running cells; fix save issue #762
@jfbercher
Copy link
Member

The issue is solved in #795. This can be closed now.

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

No branches or pull requests

3 participants