[New-bugs-announce] [issue45226] Misleading error message when pathlib.Path.symlink_to() fails with permissions error

Maor Feldinger report at bugs.python.org
Thu Sep 16 21:06:02 EDT 2021


New submission from Maor Feldinger <rounder236 at gmail.com>:

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'

----------
messages: 401996
nosy: dfntlymaybe
priority: normal
severity: normal
status: open
title: Misleading error message when pathlib.Path.symlink_to() fails with permissions error
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45226>
_______________________________________


More information about the New-bugs-announce mailing list