-
-
Notifications
You must be signed in to change notification settings - Fork 41
Fix spurious "File Changed" dialog in JupyterLab 4.1+/Notebook 7.1+ #337
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
Merged
krassowski
merged 4 commits into
jupyterlab:main
from
krassowski:fix-spurious-save-dialog
Aug 22, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8d033ab
Save current hash on the document
krassowski bf3561e
Use public API now that PR 262 in `jupyter_ydoc` is merged
krassowski a0c6d20
Use a clean solution which requires a change in JupyterLab
krassowski 9fa26e4
`jupyter-server-ydoc`: require `jupyter-server` 2.11.1 or newer
krassowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,7 @@ async def load_content(self, format: str, file_type: str) -> dict[str, Any]: | |
self.last_modified = model["last_modified"] | ||
return model | ||
|
||
async def maybe_save_content(self, model: dict[str, Any]) -> None: | ||
async def maybe_save_content(self, model: dict[str, Any]) -> dict[str, Any] | None: | ||
""" | ||
Save the content of the file. | ||
|
||
|
@@ -149,20 +149,34 @@ async def maybe_save_content(self, model: dict[str, Any]) -> None: | |
# otherwise it could corrupt the file | ||
done_saving = asyncio.Event() | ||
task = asyncio.create_task(self._save_content(model, done_saving)) | ||
saved_model = None | ||
try: | ||
await asyncio.shield(task) | ||
saved_model = await asyncio.shield(task) | ||
except asyncio.CancelledError: | ||
pass | ||
await done_saving.wait() | ||
return saved_model | ||
else: | ||
# file changed on disk, raise an error | ||
self.last_modified = m["last_modified"] | ||
raise OutOfBandChanges | ||
|
||
async def _save_content(self, model: dict[str, Any], done_saving: asyncio.Event) -> None: | ||
async def _save_content( | ||
self, model: dict[str, Any], done_saving: asyncio.Event | ||
) -> dict[str, Any]: | ||
try: | ||
m = await ensure_async(self._contents_manager.save(model, self.path)) | ||
self.last_modified = m["last_modified"] | ||
# TODO, get rid of the extra `get` here once upstream issue: | ||
# https://github.com/jupyter-server/jupyter_server/issues/1453 is resolved | ||
model_with_hash = await ensure_async( | ||
self._contents_manager.get( | ||
self.path, | ||
content=False, | ||
require_hash=True, # TODO require version supporting hash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will address this one before merging. |
||
) | ||
) | ||
return {**m, "hash": model_with_hash["hash"]} | ||
finally: | ||
done_saving.set() | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.