9

A frustrating and persistent error keeps popping up on my Jupyter Notebook:

The save operation succeeded, but the notebook does not appear to be valid. The validation error was:

Notebook validation failed: Additional properties are not allowed ('id' was unexpected):
{
 "metadata": {
  "trusted": true
 },
 "id": "breathing-seventh",
 "cell_type": "code",
 "source": "import pandas as pd\nimport numpy as np\nimport re\nimport datetime\n\nimport json\nimport os\nimport copy\n\nimport seaborn as sns\nimport matplotlib.pyplot as plt",
 "execution_count": 1,
 "outputs": []
}

It points to my imports column which contains:

import pandas as pd
import numpy as np
import re
import datetime

import json
import os
import copy

import seaborn as sns
import matplotlib.pyplot as plt

I'm also using Plotly in the notebook and I'm unsure if the error was caused by Plotly. I looked up the error and used the fixes mentioned here but the error still persists.

Please Advise.

The Singularity
  • 2,428
  • 3
  • 19
  • 48

4 Answers4

14

This is due to a fairly recent change in nbformat, which was described in detail here. Basically, nbformat 4.5 introduced these id tags (which you'll probably find in every cell if you look for them), so every notebook stored in an earlier format should not have those tags — if an early-format notebook has them, it's considered an error.

So somehow your notebook was partially updated to have id tags, but not the nbformat listed in the notebook's metadata. This has also happened to me, and it's surely a bug. (I think the update is supposed to happen via nbformat, in which v5.1.1 will automatically convert 4.x up to 4.5; but I have 5.1.2. That and every other package are as up-to-date as conda will give me, and I've restarted my jupyter server.)

Anyway, the way to solve this problem is to open up your notebook in a text editor (which could be Jupyter Notebook's built-in text editor if you temporarily change the .ipynb extension to .txt). Scroll to the very bottom, where the last few lines should look something like this:

 },
 "nbformat": 4,
 "nbformat_minor": 1
}

You should be safe to change that nbformat_minor number to 5, save the file, and open the notebook again as usual. You won't get those notifications again.

Mike
  • 19,114
  • 12
  • 59
  • 91
  • I did this but now I get a `'Unsupported nbformat version 5'` error. Any idea what may be causing this? – vftw Oct 09 '21 at 20:39
  • 2
    Are you sure you set `nbformat_minor` to 5, but left `nbformat` as 4? Have you updated all your notebook-related packages? – Mike Oct 10 '21 at 12:08
  • 1
    Oh, you're right. I changed `nbformat` to 5 and that's why it wasn't working. Thank you :) – vftw Oct 10 '21 at 19:36
  • What a wonderful answer, thanks for this. Solved the issue in one shot. – Abhimanyu Shekhawat Dec 14 '22 at 15:28
  • If this minor version upgrade is safe (we implicitly assume here that major version is the same), it could be arguably done automatically by Jupyter metadata validation code... (`nbformat==5.8.0` still does not do it) so why not open a Github Issue? – mirekphd Mar 25 '23 at 17:55
  • @mirekphd I haven't run into this at all recently. But if you're running into it — and especially if you can provide details — you should absolutely feel free to open an issue. – Mike Mar 25 '23 at 21:32
  • Hand-editing the minor format into the notebook file did not solve the problem for me. The next thing I tried was to open each offending file in Jupyter and save it right away. This added the expected `id` as needed. No more warnings from Sphinx when building. – BarryPye Apr 27 '23 at 01:09
0

I had this error with older notebooks in virtualenvs with older python packages. It usually disappears when I update all my python packages in that virtualenv.

Toby
  • 2,174
  • 4
  • 22
  • 32
  • I've tried updating a few packages that were mentioned in other questions but still hasn't fixed the issue – The Singularity Mar 03 '21 at 05:47
  • I wasn't selective, I just updated all of them so I can't tell you which ones mattered. But I suspect it is the jupyter-related ones. – Toby Mar 03 '21 at 06:38
  • Well I've updated the Juptyer ones but I can't seem to figure out why it points elsewhere – The Singularity Mar 03 '21 at 06:40
  • It just points to the first cell that has this 'id' key which happens to be your the cell with your imports. – Toby Mar 03 '21 at 08:41
0

I was able to solve this by running

conda update --all
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Alauddin Sabari
  • 181
  • 1
  • 5
0

I faced this problem when I pasted the cells from notebook-1 to notebook-2.

The simple solution is if you have your code in a cell that you would intend to reuse, then don't copy the cell but only copy the content in the cell.

In this way, I was able to resolve the error.

acesaif
  • 192
  • 1
  • 3
  • 16