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

Opening markdown notebook with empty frontmatter in Jupyter Lab raises exception #1070

Closed
tillahoffmann opened this issue Jun 2, 2023 · 1 comment · Fixed by #1080
Closed

Comments

@tillahoffmann
Copy link

Attempting to open a markdown file with empty frontmatter in Jupyter Lab raises an AttributeError. E.g., consider the simple document.

---

---

This file has empty frontmatter.

Loading the yaml frontmatter returns None, and it is not possible to open the notebook. Adding a dummy variable resolves the issue because the frontmatter is not None. If there is no frontmatter block, the Python representation presumably defaults to an empty dict which avoids the error.

[W <datetime> ServerApp] wrote error: "'NoneType' object has no attribute 'get'"
Traceback (most recent call last):
    File "/.../jupytext/contentsmanager.py", line 217, in get
    model["content"] = reads(
    File "/.../jupytext/jupytext.py", line 367, in reads
    format_name = read_format_from_metadata(text, ext) or fmt.get("format_name")
    File "/.../jupytext/formats.py", line 297, in read_format_from_metadata
    metadata = read_metadata(text, ext)
    File "/.../jupytext/formats.py", line 284, in read_metadata
    header.get("jupytext", {})
AttributeError: 'NoneType' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    File "/.../tornado/web.py", line 1786, in _execute
    result = await result
    File "/.../jupyter_server/services/contents/handlers.py", line 122, in get
    self.contents_manager.get(
    File "/.../jupytext/contentsmanager.py", line 230, in get
    raise HTTPError(500, str(err))
tornado.web.HTTPError: HTTP 500: Internal Server Error ('NoneType' object has no attribute 'get')

This is on macOS 13.3.1 with Python 3.10 and the following dependencies.

jupyter-events==0.6.3
jupyter-lsp==2.1.0
jupyter_client==8.2.0
jupyter_core==5.3.0
jupyter_server==2.5.0
jupyter_server_terminals==0.4.4
jupyterlab==4.0.0
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.7
jupyterlab_server==2.22.1
jupytext==1.14.5
@mwouts
Copy link
Owner

mwouts commented Jun 8, 2023

Thanks @tillahoffmann for reporting this. It should be easy to add a test and a fix. I'll have a look soon.

mwouts added a commit that referenced this issue Jun 20, 2023
mwouts added a commit that referenced this issue Jun 20, 2023
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 a pull request may close this issue.

2 participants