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
pathlib.resolve(strict=False) only includes first child #74363
Comments
According to the documentation https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve The current behavior is not consistent with this, and only appends the first remainder. For example: |
I can reproduce this bug. This behavior is really confusing. |
Pull Request (PR 1649) treats this as a documentation problem. I would argue that the documentation is correct and this is a bug in the code. The "I would prefer it if Path.resolve() resolved symlinks until it hits The documented behaviour also seems much more useful than the current behaviour. |
This is definitely a bug if it really behaves as described. PRs for fixing the functionality are welcome - I'm inclined to say fix it in 3.6 as well, but it might be too big a behavioural change if people are already working around it. |
In Windows/Python 3.6, the behavior matches the documented one, so this could actually be an important silent bug when executing a code wrote for Windows in another OS. I'd argue to fix it in 3.6 too. |
By the way, I'm pasting what I said on the PR here: For what it's worth, this bug was the cause of an important downtime in our organization, because someone needed to normalize a path that was later passed to a .mkdir(parents=True), and it was, in some cases, silently doing the mkdir of a wrong path instead of creating all the parents. |
This is definitely a bug and I think the fixes should be backported. |
Ah, didn't catch that it doesn't occur on Windows - that explains why I've never seen it before. Yes, definitely fix and backport. Adding the RMs in case they want to delay any upcoming releases to get the fix. |
I agree bpo-30177 is not a suitable fix for this issue, as it fixes the doc instead of fixing the actual underlying bug in the function behavior. This bug can lead to files being added to the wrong (parent) directory, which is quite critical. |
We have less than 2 weeks until cutoff for 3.6.2 so it would be great if someone would take this on. |
I'm on it. |
The initial fix should be easy: --- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -329,8 +329,6 @@ class _PosixFlavour(_Flavour):
if e.errno != EINVAL:
if strict:
raise
- else:
- return newpath
# Not a symlink
path = newpath However, the trick is going to be in the tests, which are shared between POSIX and Windows - and are apparently passing on Windows right now. I'm not entirely sure why that is, but it may not be as simple here as "works on POSIX". |
Ah, looks like they require symlinks for the whole test, which means you need to be admin when running them on Windows. Zach - do we have any buildbots running as admin for symlink tests? |
I added a fix for the tests and the code. |
The privilege to create symlinks isn't filtered out of a standard user's token. Are there any buildbots already running as a standard user? In that case it may be simpler to modify the user's rights via secpol.msc: Local Policies -> User Rights Assignment -> Create symbolic links. Support could also be added for the new feature in Windows 10 to allow unprivileged creation of symlinks when the system is in developer mode and the flag SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 1 is used. A keyword-only option to use this flag could be backported to 3.6 and enabled by default in 3.7. |
No, as far as I know. I just took Eryk's suggestion and gave the buildslave user on my Windows 8.1 bot rights to create symbolic links, though. It's now rebooting after updates, we'll see how it does shortly. |
So, I asked a friend to check again with a more recent Python version on Windows and he can't reproduce the documented behavior, so the bug seems to also be present on Windows. My patch doesn't address that for now, which explains why the build fails (and why it was working before). |
I updated the PR to fix the Windows part of the issue thanks to Zachary who gave me access to a Windows machine. |
The code has been reviewed by (the other) Antoine, I guess there is now everything needed to merge it? |
As usual, I can easily hit merge but may not be able to get to the backport immediately. Someone else can feel free to cherrypick and submit the PRs and I'll hit merge on them. We should also watch the buildbots for failures though before backporting. Particularly in this area, they should have better coverage than the PR checks. |
The only backport was for 3.6 as the previous versions don't have the strict= parameter. PR submitted here: #1985 |
Good point about not needing 3.5. Buildbots were clean, so I merged it. Thanks Antoine! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: