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

Ensure that cell ids persist after save #5928

Merged
merged 2 commits into from
Jan 12, 2021
Merged

Ensure that cell ids persist after save #5928

merged 2 commits into from
Jan 12, 2021

Conversation

mishaschwartz
Copy link
Contributor

Summary

This PR ensures that if an 'id' field exists for a cell when the notebook is loaded, the same 'id' value is saved for the given cell when the notebook is saved.

The previous behaviour was that a new random 'id' value was generated every time for each cell.

Details

As of nbformat schema 4.5, cells now have a mandatory 'id' field for each cell:

If this field does not exist for a given cell, nbformat will generate a new value for that field.

When a cell is loaded by notebook using the fromJson function, this 'id' field is ignored and when the cell is saved, nbformat sees there is no 'id' and randomly generates a new one.

With this PR, the 'id' field is saved to the cell data and then sent back to nbformat when the cell is saved so the cell id remains consistent between saves.

This PR also ensures that when cells are copied, the cell 'id' is removed, meaning that nbformat will generate a new id for it when it is saved. This is required because cell ids must be unique within a notebook.

Why this is important

Tools, plugins, etc. that use cell ids will expect the cell ids to remain consistent between saves. Use of ids in plugins is one of the main reasons for adding the id field in the first place:

Copy link
Member

@kevin-bates kevin-bates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me - thank you @mishaschwartz.

Since this is more front-end/notebook behavior, I'd prefer someone more familiar with that aspect of things to take a look prior to merging. @jasongrout, @MSeal, @willingc - are any of you (or someone else) able to review this?

@kevin-bates
Copy link
Member

Hi @mishaschwartz - sorry for the delay. Let's give this a couple more days for someone with familiarity with the front-end to chime in. If no response by then, I'll go ahead and merge.

@mishaschwartz
Copy link
Contributor Author

@kevin-bates Thanks for the update. That sounds like a good plan to me.

Copy link
Member

@Zsailer Zsailer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. 👍

@MSeal
Copy link

MSeal commented Jan 12, 2021

Awesome! Thoughts on promoting the nbformat package out of alpha once this merges?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants