Systems-Modeling / SysML-v2-Release

The latest incremental release of SysML v2. Start here.
GNU Lesser General Public License v3.0
457 stars 64 forks source link

MissingIDFieldWarning warning in SysML jupyter notebooks may cause an issue in the future #88

Open KlausGPaul opened 6 months ago

KlausGPaul commented 6 months ago

Description

When creating a new SysML notebook, the console displays the following warning:

/home/.../anaconda3/lib/python3.10/site-packages/notebook/services/contents/manager.py:353: MissingIDFieldWarning: Cell is missing an id field, this will become a hard error in future nbformat versions. You may want to use `normalize()` on your notebooks before validations (available since nbformat 5.1.4). Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future.
  validate_nb(model['content'])

Environment

Freshly installed ubuntu 24.03 LTS minimal for ARM, running in a virtual UTM machine on a Mac Arm host. Environment

Impact

None at this stage as this is a warning only, but may cause an issue in the future.

Workaround

I found https://stackoverflow.com/questions/75632445/anaconda-jupyter-notebook-and-missingidfieldwarning and used the proposed fix:

import nbformat

with open("problematic_notebook.ipynb", "r") as file:
    nb_corrupted = nbformat.reader.read(file)

nbformat.validator.validate(nb_corrupted)
# <stdin>:1: MissingIDFieldWarning: Code cell is missing an id field, 
# this will become a hard error in future nbformat versions. 
# You may want to use `normalize()` on your notebooks before validations (available since nbformat 5.1.4). 
# Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future.

nb_fixed = nbformat.validator.normalize(nb_corrupted)
nbformat.validator.validate(nb_fixed[1])
# Produces no warnings or errors.

with open("fixed_notebook.ipynb", "w") as file:
    nbformat.write(nb_fixed[1], file)
ManPython commented 2 months ago

This same.. notebook/services/contents/manager.py:353: MissingIDFieldWarning: Code cell is missing an id field, this will become a hard error in future nbformat versions. You may want to usenormalize()on your notebooks before validations (available since nbformat 5.1.4). Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future. validate_nb(model['content'])

ManPython commented 2 months ago

The problem prevent to save file .ipynb ;/ - Forbidden