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

Solving bug in rename function #6735

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ayushjariyal
Copy link

Fix #6725

Updated the condition to raise an appropriate error message (Destination already exists) when the path exists, improving code readability and correctness.

Copy link
Contributor

@khsrali khsrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ayushjariyal for your contribution, please apply the review.

if not self.isdir(newpath):
raise OSError(f'Destination {newpath} does not exist')

if self.isfile(newpath) or self.isdir(newpath):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.isfile(newpath) or self.isdir(newpath):
if self.path_exists(newpath):
raise OSError(f'Destination {newpath} already exists')

maybe this is easier, and perhaps more readable.
Also I'm not entirely sure, if existing symlinks would get caught by self.isfile

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also get rid of the comments above, line 1374-1377

@ayushjariyal
Copy link
Author

@khsrali , I have made the changes as per your instructions. Could you please review them?

@khsrali
Copy link
Contributor

khsrali commented Jan 29, 2025

@khsrali , I have made the changes as per your instructions. Could you please review them?

Please check here https://github.com/aiidateam/aiida-core/pull/6735/files
your files have merge conflicts. please fix that first.

@ayushjariyal
Copy link
Author

@khsrali I solved the merge conflict. Can you please check it?

@khsrali
Copy link
Contributor

khsrali commented Jan 29, 2025

bro, apply the review carefully 🥲
#6735 (comment)

Copy link
Collaborator

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am quite confused by this bug. Does it mean that the function never worked at all?
Is it used anywhere else in the codebase? Would be good to have a test if possible.

raise OSError(f'Destination {newpath} does not exist')

if self.path_exists(newpath):
raise OSError(f'Destination {newpath} already exist')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring on line 1360 needs fixing. (github does not allow me to comment on that line)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the docstring on line 1360, it states that OSError is used for both cases—when oldpath and newpath both are not found—which needs to be fixed. However, is it okay to use specific errors (FileNotFoundError and FileExistsError) instead of OSError?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                   :raises OSError: if oldpath is not found

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general. you are right FileNotFoundError might be a better fit for such cases, as with OSError is not immediately clear what's the error case.

However, please note OSError is the parent of FileNotFoundError

 └── Exception
      └── OSError
           ├── FileNotFoundError
           ├── PermissionError
           ├── IsADirectoryError
           ├── NotADirectoryError

For the sake of consistency --I assume-- OSError was chose to raise from our Transport class with proper message. This way it's easier to handle, when adopting any of the Transport plugins.

@khsrali
Copy link
Contributor

khsrali commented Jan 30, 2025

I am quite confused by this bug. Does it mean that the function never worked at all? Is it used anywhere else in the codebase? Would be good to have a test if possible.

yes, apparently never used across the interface 🥲

Agreed, adding tests is always a good idea! @ayushjariyal can you please write tests for this function? you can look for file test_all_plugins.py get inspiration from there and add your test with name def test_rename in it.
It's important before pushing you make sure it works, using pytest test_all_plugins.py::test_rename -s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transport: SshTransport bug in method rename
3 participants