jupyterlab / jupyterlab_server

A set of server components for JupyterLab and JupyterLab like applications

Home Page:http://jupyterlab-server.readthedocs.io/en/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to Navigate Notebooks via URL: 'Path Not Found' Error

gnadrault opened this issue ยท comments

Description

When attempting to open a specific notebook in JupyterLab using the file path URL (e.g., http://127.0.0.1:8888/lab/tree/work/my_notebook.ipynb), a popup with the error message "Path Not Found" appears. Consequently, the notebook fails to open.

image

Reproduce

  1. Start an instance of JupyterLab, I use the docker image jupyter/scipy-notebook:lab-4.0.7
  2. Create a new notebook
  3. Navigate to JupyterLab with the URL (e.g., http://127.0.0.1:8888/lab/tre) providing a bad path. Observe the error message "Path Not Found" is displayed.
  4. Attempt to navigate to the previously created notebook using the URL (e.g., http://127.0.0.1:8888/lab/tree/work/my_notebook.ipynb). Notice that the same "Path Not Found" error persists, making navigation to the notebook with the URL impossible.

Expected behavior

After providing a valid path in the URL, such as the path of a previously created notebook, the user should be able to navigate to the notebook without encountering a "Path Not Found" error.

Context

  • Operating System and version: Windows 10, WSL Ubuntu 22.04, Docker Desktop
  • Browser and version: Chrome 120
  • JupyterLab version: version 4.0.7, using jupyter/scipy-notebook:lab-4.0.7 docker image
Command Line Output No error message in the output
Browser Output
Showing error: {message: 'The path: /lab/tre was not found. JupyterLab redirected to: /'}message: "The path: /lab/tre was not found. JupyterLab redirected to: /"[[Prototype]]: Object

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! ๐ŸŽ‰

This is a duplicate of jupyterlab/jupyterlab#12768, but I'm going to leave it open, because even though the JupyterLab issue was opened first, the problem is almost certainly in this regular expression in JupyterLab Server:

MASTER_URL_PATTERN = (
r"/(?P<mode>{}|doc)(?P<workspace>/workspaces/[a-zA-Z0-9\-\_]+)?(?P<tree>/tree/.*)?"
)

In short, this does not capture solely valid URLs, such as those starting with /lab/tree. We need to intercept malformed paths after /lab/ to prevent this from occurring.

Hi @JasonWeill, this above issue is because of directly referencing the dictionary object instead of creating a copy in Python. This leads to unintended shared state, where modifications made to the dictionary in one part of the code affect other references to the same dictionary object.

page_config = super().get_page_config()

This makes a direct access to the page_config dictionary object, meaning that appending the notFoundUrl to this page_config persists throughout the instance. As a consequence, accessing the correct URL after this operation continues to trigger the same error mentioning the same path which is captured while accessing the wrong path.

page_config["notFoundUrl"] = self.request.path

So, creating a shallow copy of the object fixes this issue.๐Ÿ‘‡

page_config = super().get_page_config().copy()

I have raised a PR for this, please have a look into it.