This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misleading error message when pathlib.Path.symlink_to() fails with permissions error
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barneygale, dfntlymaybe
Priority: normal Keywords:

Created on 2021-09-17 01:06 by dfntlymaybe, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg401996 - (view) Author: Maor Feldinger (dfntlymaybe) Date: 2021-09-17 01:06
Reproduction Steps:
-------------------
Create a symlink in a directory without permissions:

>>> from pathlib import Path
>>> 
>>> target = Path('/tmp/tmp/target')                                                                                                                                                                                                                                                                                       
>>> src = Path('/tmp/tmp/src')                                                                                                                                                                                                                                                                                             
>>> src.symlink_to(target)

Actual:
-------
Permission error shows reversed order:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/pathlib.py", line 1382, in symlink_to
    if self._closed:
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/pathlib.py", line 445, in symlink
    def symlink(a, b, target_is_directory):
PermissionError: [Errno 13] Permission denied: '/tmp/tmp/target' -> '/tmp/tmp/src'

Expected:
---------
Same as os.symlink the permission error should show the right symlink order:

>>> import os
>>>
>>> os.symlink(str(src), str(target))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: '/tmp/tmp/src' -> '/tmp/tmp/target'
msg402277 - (view) Author: Barney Gale (barneygale) * Date: 2021-09-20 20:03
`os.symlink()` and `pathlib.Path.symlink_to()` have reversed argument orders, but in the repro steps you're supplying arguments in the same order.
msg402327 - (view) Author: Maor Feldinger (dfntlymaybe) Date: 2021-09-21 16:53
Oh I see what you mean, sorry about that, maybe the comperison to `os.symlink()` was wrong.

It still feels wrong to me with since I am trying to make src symlink(point) to target and in the error message it looks like I am trying to do the other way around.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89389
2021-09-21 16:53:29dfntlymaybesetmessages: + msg402327
2021-09-20 20:03:55barneygalesetnosy: + barneygale
messages: + msg402277
2021-09-17 01:13:26dfntlymaybesetcomponents: + Library (Lib)
2021-09-17 01:06:01dfntlymaybecreate