mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.64k stars 386 forks source link

writing a qmd in IPython or jupyterlab prints a validation error #999

Open machow opened 2 years ago

machow commented 2 years ago

Hello, when I open a qmd paired with a ipynb in jupyter lab, and then attempt to save it, I get this error:

    Failed validating 'additionalProperties' in code_cell:

    On instance['cells'][1]:
    {'cell_type': 'code',
     'execution_count': None,
     'id': 'd5614329',
     'metadata': {},
     'outputs': ['...0 outputs...'],
     'source': '#| output: true\n1 + 1'}

It looks like some validation process run by nbformat (?) is logging an error for v4.4 notebooks. For example, if I run this code in IPython it works, but prints the same error as above (note that no error message occurs in the regular python repl):

from jupytext import reads, writes

nb = reads("""
---
title: Some title
jupyter:
  jupytext:
    formats: 'qmd:quarto,ipynb'
    text_representation:
      extension: .qmd
      format_name: quarto
      format_version: '1.0'
      jupytext_version: 1.14.1
  kernelspec:
    display_name: Python 3 (ipykernel)
    language: python
    name: python3
---

```{python}
#| output: true
1 + 1

""")

writes(nb, fmt="qmd")



I noticed that `quarto convert` by default doesn't use v4.5, but it can with a `--with-ids` flag ([code here](https://github.com/quarto-dev/quarto-cli/blob/19f542286a11d55cef5ee14dedb08fb12ae50639/src/core/jupyter/jupyter.ts#L249)).  I wonder if one way to avoid this printed error is if (for quarto versions that support it) we use the flag to save notebooks as v4.5?

I tested with a few different versions of nbformat (including down to 5.1.3), but wasn't able to get rid of the message.
mwouts commented 2 years ago

Hi @machow , thank you for reporting this.

Well I am seeing a similar issue on our CI at #1002. I think we have two options here:

  1. You could downgrade the version of nbformat. To make sure that you're using the version you think you are, I would suggest that you print nbformat.__version__ in the same Python env where you are able to reproduce the issue. Then you'll need to do the same in your Jupyter environment.
  2. You could also report the issue at https://github.com/quarto-dev/quarto-cli/, where the actual qmd to ipynb converter is maintained.