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

JN 7.0 → Impossible to save/keep Trusted state of a notebook #6988

Closed
MichalRIcar opened this issue Jul 28, 2023 · 11 comments · Fixed by #7036
Closed

JN 7.0 → Impossible to save/keep Trusted state of a notebook #6988

MichalRIcar opened this issue Jul 28, 2023 · 11 comments · Fixed by #7036

Comments

@MichalRIcar
Copy link

Hello, I am playing with JN 7.0 the latest version and it is truly an amazing job, thank you for your work and effort!

The issue below is true only for JN 7, all other versions JN <7 keep Trusted state.

I just can’t figure out how to convince new JN to keep state “Trusted” - I open a notebook, change to Trusted from Not Trusted, save it. Close it and reopen it and state is again “Not Trusted”.

I tried it on several machines and notebooks and no luck - always falls back to Not Trusted.
Even “jupyter trust X.ipynb” command doesn’t solve the problem - it reports back “Notebook already signed: X.ipynb”. However, once opened it is in the Not Trusted state.

Can you guide me how to fix it?

Note:
The only possible link to this issue I see is a server’s message:
“This version of python seems to be incorrectly compiled
(internal generated filenames are not absolute).
This may make the debugger miss breakpoints.
Related bug: Issue 1666807: Incorrect file path reported by inspect.getabsfile() - Python tracker

But as previous versions of Jupyter didn’t have this message, I have no clue how to fix it.

Thanks,
Michal

@MichalRIcar MichalRIcar added bug status:Needs Triage Applied to issues that need triage labels Jul 28, 2023
@jtpio
Copy link
Member

jtpio commented Jul 28, 2023

Thanks @MichalRIcar for reporting.

Notebook 7 reuses the same trust mechanism as in JupyterLab.

There were some improvements to the trust state that landed in Notebook 7: jupyterlab/jupyterlab#14025

But it looks like there are indeed some issues left. Would you be able to check with JupyterLab to see if it behaves the same? If yes we'll probably have to fix it in JupyterLab first.

@MichalRIcar
Copy link
Author

MichalRIcar commented Jul 28, 2023

@jtpio You are right - in JupyterLab the same notebook is denoted as Trusted, however, in JN as Not Trusted.

@MichalRIcar
Copy link
Author

@jtpio

Hi, in JupyterLab the notebook in question is denoted as Trusted, however, the same one in JN 7 as Not Trusted.

I believe it is connected with a fact that the notebook was created in older version of JN an somehow new JN has some issue with it, but doesn’t report anything anywhere.

I am wondering, is there some sort of a tool which will check possible internal errors of a notebook - its structure etc. which might cause some issues in JN 7? Or only solution is to copy paste the code to newly created JN under v7?

When I create a new notebook under v7 then it keeps Trusted state as expected behavior.

@jtpio
Copy link
Member

jtpio commented Aug 1, 2023

Hi, in JupyterLab the notebook in question is denoted as Trusted, however, the same one in JN 7 as Not Trusted.

Normally both JupyterLab and Notebook 7 share the same trust implementation.

I am wondering, is there some sort of a tool which will check possible internal errors of a notebook - its structure etc. which might cause some issues in JN 7? Or only solution is to copy paste the code to newly created JN under v7?

Would it be possible to share a sample notebook for testing?

Otherwise maybe using nbformat can highlight some issues in the notebook: https://nbformat.readthedocs.io/en/latest/api.html

@MichalRIcar
Copy link
Author

@jtpio , thank you, I will use nbformat and try to track the root of it. I will share it together with a notebook too once I will do a basic analysis. I believe during tomorrow.

@MichalRIcar
Copy link
Author

MichalRIcar commented Aug 3, 2023

Hello,

I played with the notebook in question and nbformat didn't provide me any helpful information.

You can find the notebook under the link below
https://drive.google.com/file/d/10rBLlwjkzDo2kW--8mD7_EHUDBoTBpPT/view?usp=sharing

Please let me know if there is a way to fix the Not Trusted status (except copy past cell by cell to a new notebook).

Thank you

@RRosio
Copy link
Collaborator

RRosio commented Aug 8, 2023

Hi @MichalRIcar, thank you for the follow up information. This was fixed in JupyterLab 4, jupyterlab/jupyterlab#9765, and as the code is shared with Notebook 7, if it is a problem in Notebook 7, it should be appearing in JupyterLab 4 as well.

@MichalRIcar
Copy link
Author

MichalRIcar commented Aug 8, 2023

Hello @RRosio, sadly the situation is that JL state is "Trusted", however JN state is "Not Trusted", even though when verifing JN by “jupyter trust X.ipynb” the message is “Notebook already signed: X.ipynb”, yet when I open it the state is still "Not Trusted".

You can verify this behavior by the shared link above - it is somehow broken notebook - empty one but impossible to keep state Trusted → open it - change the state to Trusted - save it - close it - open it again - state in JN will be "Not Trusted"; in JL it will be "Trusted".

Important note: this Jupyter Notebook behavior is only true for JN v7; JN < 7 keeps Trusted state.

@RRosio RRosio added regression and removed status:Needs Triage Applied to issues that need triage status:Needs Info labels Aug 15, 2023
@krassowski
Copy link
Member

It appears that there is indeed an issue in Notebook 7: it uses the old code for indicator status which counts non-code cells in:

/**
* Check if a notebook is trusted
* @param notebook The notebook to check
* @returns true if the notebook is trusted, false otherwise
*/
const isTrusted = (notebook: Notebook): boolean => {
const model = notebook.model;
if (!model) {
return false;
}
const cells = Array.from(model.cells);
const trusted = cells.reduce((accum, current) => {
if (current.trusted) {
return accum + 1;
} else {
return accum;
}
}, 0);
const total = cells.length;
return trusted === total;
};

Whereas the fix upstream changed it to only count code cells (jupyterlab/jupyterlab@ed7c879):

https://github.com/jupyterlab/jupyterlab/blob/19fa54fcbf3e684d7c4466807af549ba0d565ad2/packages/notebook/src/truststatus.tsx#L240-L259

@krassowski
Copy link
Member

So in fact there is no problem with the notebook not being trusted (this is why you see "Notebook already signed"), it is just that the label displayed is wrong.

@adigaboy
Copy link
Contributor

adigaboy commented Sep 7, 2023

Opened a PR to fix this issue:
#7036

@jtpio jtpio linked a pull request Sep 8, 2023 that will close this issue
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants