Skip to content

Commit e789676

Browse files
Run pre_save_hook before model check (#643)
1 parent 4d2f85a commit e789676

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

jupyter_server/services/contents/filemanager.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ def save(self, model, path=""):
433433
"""Save the file model and return the model with no content."""
434434
path = path.strip("/")
435435

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

444-
self.run_pre_save_hook(model=model, path=path)
445-
446446
try:
447447
if model["type"] == "notebook":
448448
nb = nbformat.from_dict(model["content"])
@@ -757,16 +757,15 @@ async def save(self, model, path=""):
757757
"""Save the file model and return the model with no content."""
758758
path = path.strip("/")
759759

760+
os_path = self._get_os_path(path)
761+
self.log.debug("Saving %s", os_path)
762+
self.run_pre_save_hook(model=model, path=path)
763+
760764
if "type" not in model:
761765
raise web.HTTPError(400, u"No file type provided")
762766
if "content" not in model and model["type"] != "directory":
763767
raise web.HTTPError(400, u"No file content provided")
764768

765-
os_path = self._get_os_path(path)
766-
self.log.debug("Saving %s", os_path)
767-
768-
self.run_pre_save_hook(model=model, path=path)
769-
770769
try:
771770
if model["type"] == "notebook":
772771
nb = nbformat.from_dict(model["content"])

jupyter_server/services/contents/largefilemanager.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def save(self, model, path=""):
1818
if chunk is not None:
1919
path = path.strip("/")
2020

21+
self.run_pre_save_hook(model=model, path=path)
22+
2123
if "type" not in model:
2224
raise web.HTTPError(400, u"No file type provided")
2325
if model["type"] != "file":
@@ -31,11 +33,10 @@ def save(self, model, path=""):
3133
raise web.HTTPError(400, u"No file content provided")
3234

3335
os_path = self._get_os_path(path)
36+
self.log.debug("Saving %s", os_path)
3437

3538
try:
3639
if chunk == 1:
37-
self.log.debug("Saving %s", os_path)
38-
self.run_pre_save_hook(model=model, path=path)
3940
super(LargeFileManager, self)._save_file(
4041
os_path, model["content"], model.get("format")
4142
)
@@ -90,6 +91,10 @@ async def save(self, model, path=""):
9091
if chunk is not None:
9192
path = path.strip("/")
9293

94+
os_path = self._get_os_path(path)
95+
self.log.debug("Saving %s", os_path)
96+
self.run_pre_save_hook(model=model, path=path)
97+
9398
if "type" not in model:
9499
raise web.HTTPError(400, u"No file type provided")
95100
if model["type"] != "file":
@@ -102,12 +107,8 @@ async def save(self, model, path=""):
102107
if "content" not in model and model["type"] != "directory":
103108
raise web.HTTPError(400, u"No file content provided")
104109

105-
os_path = self._get_os_path(path)
106-
107110
try:
108111
if chunk == 1:
109-
self.log.debug("Saving %s", os_path)
110-
self.run_pre_save_hook(model=model, path=path)
111112
await super(AsyncLargeFileManager, self)._save_file(
112113
os_path, model["content"], model.get("format")
113114
)

0 commit comments

Comments
 (0)