Skip to content

Commit a984e07

Browse files
Added Logs for get_os_path closes issue (#1336)
Co-authored-by: Steven Silvester <[email protected]>
1 parent 89c8de5 commit a984e07

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

jupyter_server/services/contents/fileio.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from tornado.web import HTTPError
1616
from traitlets import Bool
1717
from traitlets.config import Configurable
18+
from traitlets.config.configurable import LoggingConfigurable
1819

1920
from jupyter_server.utils import ApiPath, to_api_path, to_os_path
2021

@@ -165,7 +166,7 @@ def _simple_writing(path, text=True, encoding="utf-8", log=None, **kwargs):
165166
fileobj.close()
166167

167168

168-
class FileManagerMixin(Configurable):
169+
class FileManagerMixin(LoggingConfigurable, Configurable):
169170
"""
170171
Mixin for ContentsAPI classes that interact with the filesystem.
171172
@@ -203,7 +204,7 @@ def atomic_writing(self, os_path, *args, **kwargs):
203204
Depending on flag 'use_atomic_writing', the wrapper perform an actual atomic writing or
204205
simply writes the file (whatever an old exists or not)"""
205206
with self.perm_to_403(os_path):
206-
kwargs["log"] = self.log # type:ignore[attr-defined]
207+
kwargs["log"] = self.log
207208
if self.use_atomic_writing:
208209
with atomic_writing(os_path, *args, **kwargs) as f:
209210
yield f
@@ -233,7 +234,7 @@ def _copy(self, src, dest):
233234
234235
like shutil.copy2, but log errors in copystat
235236
"""
236-
copy2_safe(src, dest, log=self.log) # type:ignore[attr-defined]
237+
copy2_safe(src, dest, log=self.log)
237238

238239
def _get_os_path(self, path):
239240
"""Given an API path, return its file system path.
@@ -252,6 +253,7 @@ def _get_os_path(self, path):
252253
------
253254
404: if path is outside root
254255
"""
256+
self.log.debug("Reading path from disk: %s", path)
255257
root = os.path.abspath(self.root_dir) # type:ignore[attr-defined]
256258
# to_os_path is not safe if path starts with a drive, since os.path.join discards first part
257259
if os.path.splitdrive(path)[0]:
@@ -359,7 +361,7 @@ async def _copy(self, src, dest):
359361
360362
like shutil.copy2, but log errors in copystat
361363
"""
362-
await async_copy2_safe(src, dest, log=self.log) # type:ignore[attr-defined]
364+
await async_copy2_safe(src, dest, log=self.log)
363365

364366
async def _read_notebook(self, os_path, as_version=4, capture_validation_error=None):
365367
"""Read a notebook from an os path."""

jupyter_server/services/contents/filemanager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ def save(self, model, path=""):
458458
raise web.HTTPError(400, "No file type provided")
459459
if "content" not in model and model["type"] != "directory":
460460
raise web.HTTPError(400, "No file content provided")
461-
462461
os_path = self._get_os_path(path)
463462

464463
if not self.allow_hidden and is_hidden(os_path, self.root_dir):

tests/services/contents/test_fileio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def test_path_to_invalid(tmpdir):
139139
@pytest.mark.skipif(os.name == "nt", reason="test fails on Windows")
140140
def test_file_manager_mixin(tmpdir):
141141
mixin = FileManagerMixin()
142-
mixin.log = logging.getLogger() # type:ignore[attr-defined]
142+
mixin.log = logging.getLogger()
143143
bad_content = tmpdir / "bad_content.ipynb"
144144
bad_content.write_text("{}", "utf8")
145145
with pytest.raises(HTTPError):
@@ -161,7 +161,7 @@ def test_file_manager_mixin(tmpdir):
161161
@pytest.mark.skipif(os.name == "nt", reason="test fails on Windows")
162162
async def test_async_file_manager_mixin(tmpdir):
163163
mixin = AsyncFileManagerMixin()
164-
mixin.log = logging.getLogger() # type:ignore[attr-defined]
164+
mixin.log = logging.getLogger()
165165
bad_content = tmpdir / "bad_content.ipynb"
166166
bad_content.write_text("{}", "utf8")
167167
with pytest.raises(HTTPError):

0 commit comments

Comments
 (0)