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

Custom ContentsManager with a NoOpCheckpoints cannot open notebook, raises Unhandled error #1348

Open
miraculixx opened this issue Oct 25, 2023 · 1 comment
Labels

Comments

@miraculixx
Copy link

miraculixx commented Oct 25, 2023

Description

Implementing a NoOpCheckpoints checkpoints class for a custom ContentsManager results in a Unhandled error being raised when opening a notebook in Jupyter Lab.

Reproduce

  1. Create a new ContentsManager class (e.g. subclass FileContentsManager)
  2. Create the NoOpCheckpoints as shown in the documentation
  3. Set the checkpoints_class = NoOpCheckpoints trait
  4. Run Jupyter lab and try creating a new notebook
  5. This will result in client error shown below (screenshot) and in the severs' log (traceback in command line output)

image

Expected behavior

This should work, or the documentation for NoOpCheckpoints should be changed.

Context

This used to work. I did not manage to find the jupyter part and version (client or server) that has introduced the issue.

  • Operating System and version: Linux Mint 21.2 Victoria base: Ubuntu 22.04 jammy
  • Python 3.10.12,
  • Browser and version: Google Chrome Version 118.0.5993.88 (Official Build) (64-bit)
  • Jupyter Server version:jupyter_server==2.9.0
Troubleshoot Output
$ pip freeze | grep -i jup
jupyter-events==0.6.3
jupyter-lsp==2.2.0
jupyter-telemetry==0.1.0
jupyter_client==8.4.0
jupyter_core==5.4.0
jupyter_server==2.9.0
jupyter_server_terminals==0.4.4
jupyterhub==4.0.2
jupyterlab==4.0.7
jupyterlab-pygments==0.2.2
jupyterlab_server==2.24.0
Command Line Output
[W 2023-10-25 11:57:18.899 ServerApp] wrote error: 'Unhandled error'                                                                                          
    Traceback (most recent call last):                                                                                                                        
      File "/.../lib/python3.10/site-packages/tornado/web.py", line 1786, in _execute                                     
        result = await result                                                                                                                                 
      File "/.../python3.10/site-packages/jupyter_server/services/contents/handlers.py", line 311, in post            
        url_escape(checkpoint["id"]),                                                                                                                         
    TypeError: 'NoneType' object is not subscriptable                                                                                                         
[E 2023-10-25 11:57:18.900 ServerApp] {                                                                                                                       
      "Host": "localhost:8888",                                                                                                                               
      "Accept": "*/*",                                                                                                                                        
      "Referer": "http://localhost:8888/lab/workspaces/auto-i/tree/Untitled.ipynb",                                                                           
      "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
Browser Output
Paste the output from your browser Javascript console here, if applicable.
@miraculixx miraculixx added the bug label Oct 25, 2023
@miraculixx miraculixx changed the title NoOpCheckpoints Custom ContentsManager with a NoOpCheckpoints cannot open notebook, raises Unhandled error Oct 25, 2023
@miraculixx
Copy link
Author

Changing the NoOpsCheckpoints implementation slightly removes the issue (added the checkpoint_model() method and called this method in create_file_checkpoint() and create_notebook_checkpoint(), hint taken from FileContentsManager)

from IPython.utils.tz import utcnow
from jupyter_server.services.contents.checkpoints import GenericCheckpointsMixin, Checkpoints


class NoOpCheckpoints(GenericCheckpointsMixin, Checkpoints):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.log.info("**** NoOpCheckpoints initialized")

    def checkpoint_model(self):
        info = {
            "id": "",
            "last_modified": utcnow()
        }
        return info

    def create_file_checkpoint(self, content, format, path):
        """ -> checkpoint model"""
        return self.checkpoint_model()

    def create_notebook_checkpoint(self, nb, path):
        """ -> checkpoint model"""
        return self.checkpoint_model()

    def get_file_checkpoint(self, checkpoint_id, path):
        """ -> {'type': 'file', 'content': <str>, 'format': {'text', 'base64'}}"""

    def get_notebook_checkpoint(self, checkpoint_id, path):
        """ -> {'type': 'notebook', 'content': <output of nbformat.read>}"""

    def delete_checkpoint(self, checkpoint_id, path):
        """deletes a checkpoint for a file"""

    def list_checkpoints(self, path):
        """returns a list of checkpoint models for a given file,
        default just does one per file
        """
        return []

    def rename_checkpoint(self, checkpoint_id, old_path, new_path):
        """renames checkpoint from old path to new path"""

miraculixx added a commit to omegaml/omegaml that referenced this issue Oct 25, 2023
miraculixx added a commit to omegaml/omegaml that referenced this issue Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant