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

Run pre_save_hook before model check #643

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions jupyter_server/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def save(self, model, path=""):
"""Save the file model and return the model with no content."""
path = path.strip("/")

self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if "content" not in model and model["type"] != "directory":
Expand All @@ -441,8 +443,6 @@ def save(self, model, path=""):
os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)

self.run_pre_save_hook(model=model, path=path)

try:
if model["type"] == "notebook":
nb = nbformat.from_dict(model["content"])
Expand Down Expand Up @@ -757,16 +757,15 @@ async def save(self, model, path=""):
"""Save the file model and return the model with no content."""
path = path.strip("/")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if "content" not in model and model["type"] != "directory":
raise web.HTTPError(400, u"No file content provided")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)

self.run_pre_save_hook(model=model, path=path)

try:
if model["type"] == "notebook":
nb = nbformat.from_dict(model["content"])
Expand Down
13 changes: 7 additions & 6 deletions jupyter_server/services/contents/largefilemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def save(self, model, path=""):
if chunk is not None:
path = path.strip("/")

self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if model["type"] != "file":
Expand All @@ -31,11 +33,10 @@ def save(self, model, path=""):
raise web.HTTPError(400, u"No file content provided")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)

try:
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
super(LargeFileManager, self)._save_file(
os_path, model["content"], model.get("format")
)
Expand Down Expand Up @@ -90,6 +91,10 @@ async def save(self, model, path=""):
if chunk is not None:
path = path.strip("/")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if model["type"] != "file":
Expand All @@ -102,12 +107,8 @@ async def save(self, model, path=""):
if "content" not in model and model["type"] != "directory":
raise web.HTTPError(400, u"No file content provided")

os_path = self._get_os_path(path)

try:
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
await super(AsyncLargeFileManager, self)._save_file(
os_path, model["content"], model.get("format")
)
Expand Down