-
Notifications
You must be signed in to change notification settings - Fork 310
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
Remove Redundant Dir_Exists Invocation When Creating New Files with ContentsManager #720
Remove Redundant Dir_Exists Invocation When Creating New Files with ContentsManager #720
Conversation
…ll in PUT to maintain behavior
Thanks for submitting your first pull request! You are awesome! 🤗 |
This one needs a rebase now after merging #721 |
Hi @jhamet93 - I totally agree with the premise and removal of extraneous I'm wondering if we should instead remove the |
I agree! That was my other proposed solution in the issue after I implemented this that makes more sense like you mention. Will take a look at making the mods there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look good to me Josh - thank you. Could you please merge in the main
branch to resolve the conflicts? Also, I think filemanager.py should probably have a newline in its last character (which probably triggers the conflict 😄 ).
Kicking CI |
The |
Ah, it looks like there are some relevant test failures:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out the real test failures @blink1073.
Per my comment, this presents an interesting issue (hassle) in order to preserve parity with the REST API. I haven't looked at the various utility methods, but I think we'll need to distinguish a directory segment of a path from a filename segment of a path to do that.
if to_path is not None: | ||
to_path = to_path.strip("/") | ||
dir_exists = self.dir_exists(to_path) | ||
if not dir_exists: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably leverage the self.dir_exists(to_path)
at L483 below to avoid a redundant dir-exists check.
It's interesting, but the REST API appears to only support "copy" into a directory (typically the same directory as the source), whereas the ContentsManager also supports copy to a file, which is why the tests are failing (due to the first dir_exists()
call since to_path
represents a file).
It seems like the case that's missing here (even before this PR) is when to_path
(being either a directory or file) references a non-existent directory. The way things stand now, this will result in a 500 error similar to the following (reproduced by changing a character in the parent directory name from 'b'
to 'x'
in the test_copy
test):
tornado.web.HTTPError: HTTP 500: Internal Server Error (Unexpected error while saving file: å x/copy 2.ipynb [Errno 2] No such file or directory: '/private/var/folders/4w/qxgsbhyx1y93qlk9mnzwjryc0000gn/T/pytest-of-kbates/pytest-113/test_copy_jp_contents_manager30/å x/copy 2.ipynb')
jupyter_server/services/contents/filemanager.py:806: HTTPError
In order to preserve parity with the handler (where to_path
can only be a directory and a 404 is returned if it doesn't exist), I think some additional logic is required to check if to_path
is only a directory name or a combination of directory/file and ensure the respective directory portion exists (throwing 404 if it does not).
(Same would be needed in the async CM as well.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good eye. Made the modifications and tried to preserve the parity you mentioned with a few test cases to verify.
… into jhamet/Remove_Redundant_Invocations
Codecov Report
@@ Coverage Diff @@
## main #720 +/- ##
==========================================
- Coverage 70.80% 70.25% -0.55%
==========================================
Files 62 62
Lines 7627 7497 -130
Branches 1220 1226 +6
==========================================
- Hits 5400 5267 -133
- Misses 1850 1856 +6
+ Partials 377 374 -3
Continue to review full report at Codecov.
|
Going to close and reopen to trigger the pre-commit bot. |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thank you @jhamet93. I apologize for the delay in getting back to this.
Thanks, @jhamet93. Merging! |
Removes the redundant
ContentsManager.dir_exists
calls when creating a new file. Maintains current behavior in other known usages ofContentsManager.new_untitled
.Issue: #719