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 1 commit
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
18 changes: 8 additions & 10 deletions jupyter_server/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,15 @@ 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)
vidartf marked this conversation as resolved.
Show resolved Hide resolved
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 Expand Up @@ -757,16 +756,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
16 changes: 8 additions & 8 deletions jupyter_server/services/contents/largefilemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ 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 @@ -30,12 +34,8 @@ 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)
super(LargeFileManager, self)._save_file(
os_path, model["content"], model.get("format")
)
Expand Down Expand Up @@ -90,6 +90,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 +106,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