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: Path.mkdir can get into a recursive error loop
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: Dan Buchoff, eryksun, paul.moore, python-dev, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2017-02-01 22:46 by Dan Buchoff, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg286717 - (view) Author: Dan Buchoff (Dan Buchoff) Date: 2017-02-01 22:46
If a path has a non-existent anchor, Path.mkdir can get into a RecursionError as it tries to recursively create the parent. I expect a more sane error.

This is readily reproducible in Windows with `Path('Z:').mkdir(parents=True)`

Example execution:

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path('Z:').mkdir(parents=True)
Traceback (most recent call last):
  File "C:\Python36\lib\pathlib.py", line 1231, in mkdir
    self._accessor.mkdir(self, mode)
  File "C:\Python36\lib\pathlib.py", line 388, in wrapped
    return strfunc(str(pathobj), *args)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Z:'

During handling of the above exception, another exception occurred:

...

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36\lib\pathlib.py", line 1238, in mkdir
    self.parent.mkdir(parents=True)
  File "C:\Python36\lib\pathlib.py", line 1238, in mkdir
    self.parent.mkdir(parents=True)
  File "C:\Python36\lib\pathlib.py", line 1238, in mkdir
    self.parent.mkdir(parents=True)
  [Previous line repeated 989 more times]
  File "C:\Python36\lib\pathlib.py", line 1231, in mkdir
    self._accessor.mkdir(self, mode)
  File "C:\Python36\lib\pathlib.py", line 388, in wrapped
    return strfunc(str(pathobj), *args)
RecursionError: maximum recursion depth exceeded
msg286723 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-02-02 00:09
Might be worth checking if this is resolved with issue29079, which is already in for 3.6.1.
msg286734 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2017-02-02 01:59
This case is similar to issue 29079. It should only attempt to make the parent to handle ENOENT if self and self.parent aren't equal. Here's the snippet from Path.mkdir:

    try:
        self._accessor.mkdir(self, mode)
    except FileExistsError:
        if not exist_ok or not self.is_dir():
            raise
    except OSError as e:
        if e.errno != ENOENT:
            raise
        self.parent.mkdir(parents=True)
        self._accessor.mkdir(self, mode)
msg286999 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-04 22:57
New changeset 8061d0967988 by Steve Dower in branch '3.5':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://hg.python.org/cpython/rev/8061d0967988

New changeset 3de58a54ed98 by Steve Dower in branch '3.6':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://hg.python.org/cpython/rev/3de58a54ed98

New changeset 09c018897fb3 by Steve Dower in branch 'default':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://hg.python.org/cpython/rev/09c018897fb3
msg287000 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-04 23:00
New changeset 661c40ba59855ebe4967424fcabd41be6f799137 by Steve Dower in branch 'master':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://github.com/python/cpython/commit/661c40ba59855ebe4967424fcabd41be6f799137

New changeset 77da63372461ddeb82dbfdef86e702e43e24e1da by Steve Dower in branch 'master':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://github.com/python/cpython/commit/77da63372461ddeb82dbfdef86e702e43e24e1da

New changeset c05ffe646dc009c01365db917f0ca6b738fda69b by Steve Dower in branch 'master':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://github.com/python/cpython/commit/c05ffe646dc009c01365db917f0ca6b738fda69b
msg287001 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-04 23:00
New changeset 661c40ba59855ebe4967424fcabd41be6f799137 by Steve Dower in branch '3.6':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://github.com/python/cpython/commit/661c40ba59855ebe4967424fcabd41be6f799137

New changeset 77da63372461ddeb82dbfdef86e702e43e24e1da by Steve Dower in branch '3.6':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://github.com/python/cpython/commit/77da63372461ddeb82dbfdef86e702e43e24e1da
msg287002 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-04 23:00
New changeset 661c40ba59855ebe4967424fcabd41be6f799137 by Steve Dower in branch '3.5':
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
https://github.com/python/cpython/commit/661c40ba59855ebe4967424fcabd41be6f799137
History
Date User Action Args
2022-04-11 14:58:42adminsetgithub: 73602
2017-11-09 18:03:53serhiy.storchakasetstatus: pending -> closed
resolution: fixed
stage: commit review -> resolved
2017-04-02 13:51:12serhiy.storchakasetstatus: open -> pending
2017-04-01 05:48:30serhiy.storchakasetpull_requests: - pull_request984
2017-03-31 16:36:24dstufftsetpull_requests: + pull_request984
2017-02-04 23:00:30python-devsetmessages: + msg287002
2017-02-04 23:00:28python-devsetmessages: + msg287001
2017-02-04 23:00:25python-devsetmessages: + msg287000
2017-02-04 22:57:46steve.dowersetassignee: steve.dower
stage: needs patch -> commit review
2017-02-04 22:57:24python-devsetnosy: + python-dev
messages: + msg286999
2017-02-02 01:59:11eryksunsetversions: + Python 3.7
nosy: + eryksun

messages: + msg286734

stage: needs patch
2017-02-02 00:09:23steve.dowersetmessages: + msg286723
2017-02-01 22:47:35Dan Buchoffsettype: behavior
2017-02-01 22:46:32Dan Buchoffcreate