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

pathlib.Path.exists() on non-existent drive raises WinError instead of returning False #79873

Closed
JordanHueckstaedt mannequin opened this issue Jan 9, 2019 · 6 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@JordanHueckstaedt
Copy link
Mannequin

JordanHueckstaedt mannequin commented Jan 9, 2019

BPO 35692
Nosy @pfmoore, @pitrou, @tjguk, @zware, @eryksun, @zooba, @miss-islington
PRs
  • bpo-35692: pathlib no longer raises when checking file and directory existence #11746
  • bpo-35692: pathlib no longer raises when checking file and directory existence #11746
  • bpo-35692: pathlib no longer raises when checking file and directory existence #11746
  • [3.7] bpo-35692: pathlib no longer raises when checking file and directory existence on drives that are not ready (GH-11746) #11752
  • [3.7] bpo-35692: pathlib no longer raises when checking file and directory existence on drives that are not ready (GH-11746) #11752
  • [3.7] bpo-35692: pathlib no longer raises when checking file and directory existence on drives that are not ready (GH-11746) #11752
  • 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:

    assignee = 'https://github.com/zooba'
    closed_at = <Date 2019-02-04.07:33:25.544>
    created_at = <Date 2019-01-09.03:00:15.061>
    labels = ['3.7', '3.8', 'type-bug', 'library', 'OS-windows']
    title = 'pathlib.Path.exists() on non-existent drive raises WinError instead of returning False'
    updated_at = <Date 2019-02-04.07:33:25.543>
    user = 'https://bugs.python.org/JordanHueckstaedt'

    bugs.python.org fields:

    activity = <Date 2019-02-04.07:33:25.543>
    actor = 'steve.dower'
    assignee = 'steve.dower'
    closed = True
    closed_date = <Date 2019-02-04.07:33:25.544>
    closer = 'steve.dower'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2019-01-09.03:00:15.061>
    creator = 'Jordan Hueckstaedt'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35692
    keywords = ['patch', 'patch', 'patch']
    message_count = 6.0
    messages = ['333275', '333724', '333729', '333748', '334811', '334814']
    nosy_count = 8.0
    nosy_names = ['paul.moore', 'pitrou', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'miss-islington', 'Jordan Hueckstaedt']
    pr_nums = ['11746', '11746', '11746', '11752', '11752', '11752']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35692'
    versions = ['Python 3.7', 'Python 3.8']

    @JordanHueckstaedt
    Copy link
    Mannequin Author

    JordanHueckstaedt mannequin commented Jan 9, 2019

    Tested in 3.7.0 on windows 10.
    This looks related to https://bugs.python.org/issue22759

    >>> import pathlib
    >>> pathlib.Path(r"E:\Whatever\blah.txt").exists()  # This drive doesn't exist
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\jordanhu\AppData\Local\Continuum\anaconda2\envs\py3\lib\pathlib.py", line 1318, in exists
        self.stat()
      File "C:\Users\jordanhu\AppData\Local\Continuum\anaconda2\envs\py3\lib\pathlib.py", line 1140, in stat
        return self._accessor.stat(self)
    PermissionError: [WinError 21] The device is not ready: 'E:\\Whatever\\blah.txt'
    >>> pathlib.Path(r"C:\Whatever\blah.txt").exists() # This drive exists
    False

    @JordanHueckstaedt JordanHueckstaedt mannequin added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Jan 9, 2019
    @brettcannon brettcannon added stdlib Python modules in the Lib dir OS-windows labels Jan 9, 2019
    @zooba
    Copy link
    Member

    zooba commented Jan 15, 2019

    In bpo-22759 there was some logic applied for which errors to forward rather than hide.

    I'm inclined to agree that this one should be hidden, but it may have to be done by checking the winerror field rather than the exception type, since other PermissionErrors may mean the file is guaranteed to exist (but you can't touch it) or that the path exists up to the point where you are not allowed to see.

    I'd happily argue that since these permissions indicate that the file does not exist *for the current user* and so they should be swallowed more broadly, but I'll let Antoine make the call.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 15, 2019

    I think exists() should simply return False here. There's no reason a non-existing drive should fail differently than a non-existing parent directory.

    @pitrou pitrou added the 3.8 only security fixes label Jan 15, 2019
    @eryksun
    Copy link
    Contributor

    eryksun commented Jan 16, 2019

    There's no reason a non-existing drive should fail differently than
    a non-existing parent directory.

    The drive exists (or should) if we're getting ERROR_NOT_READY (21). It's likely a removable media device, such as an optical disc or card reader, and there's no media in the device.

    If a logical drive isn't defined at all, we should get ERROR_PATH_NOT_FOUND (from the NT status value STATUS_OBJECT_PATH_NOT_FOUND). This gets mapped to the errno value ENOENT, which is already handled. For example:

        >>> os.stat('Q:/')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Q:/'
    
        >>> pathlib.Path('Q:/whatever/blah.txt').exists()
        False

    Similarly if a UNC 'drive' doesn't exist, we should get ERROR_BAD_NET_NAME (from NT STATUS_BAD_NETWORK_NAME), which is also mapped to ENOENT:

        >>> os.stat('//some/where')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        FileNotFoundError: [WinError 67] The network name cannot be found: '//some/where'
    
        >>> pathlib.Path('//some/where/whatever/blah.txt').exists()
        False

    @zooba zooba self-assigned this Feb 3, 2019
    @zooba
    Copy link
    Member

    zooba commented Feb 4, 2019

    New changeset 2f6fae6 by Steve Dower in branch 'master':
    bpo-35692: pathlib no longer raises when checking file and directory existence on drives that are not ready (GH-11746)
    2f6fae6

    @miss-islington
    Copy link
    Contributor

    New changeset 69af439 by Miss Islington (bot) in branch '3.7':
    bpo-35692: pathlib no longer raises when checking file and directory existence on drives that are not ready (GH-11746)
    69af439

    @zooba zooba closed this as completed Feb 4, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants