Skip to content

fix: prevent FileNotFoundError when storages.touch() is called with a…#619

Open
n1teshy wants to merge 1 commit into
msiemens:masterfrom
n1teshy:fix_touch
Open

fix: prevent FileNotFoundError when storages.touch() is called with a…#619
n1teshy wants to merge 1 commit into
msiemens:masterfrom
n1teshy:fix_touch

Conversation

@n1teshy

@n1teshy n1teshy commented Jun 29, 2026

Copy link
Copy Markdown

Hi, the touch function in storages.py calls os.makedirs if create_dirs is True, but a user may unknowingly pass create_dirs as True even when the JSON file to be created is in the current working directory, in which case, the file's directory would be an empty string and FileNotFoundError would be raised by os.makedirs.

from tinydb import TinyDB

TinyDB("some.json", create_dirs=True)

Traceback (most recent call last):
File "", line 1, in
TinyDB('some.json', create_dirs=True)
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nitesh/Desktop/programming/open-source/tinydb/tinydb/database.py", line 95, in init
self._storage: Storage = storage(*args, **kwargs)
~~~~~~~^^^^^^^^^^^^^^^^^
File "/home/nitesh/Desktop/programming/open-source/tinydb/tinydb/storages.py", line 117, in init
touch(path, create_dirs=create_dirs)
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nitesh/Desktop/programming/open-source/tinydb/tinydb/storages.py", line 28, in touch
os.makedirs(base_dir)
~~~~~~~~~~~^^^^^^^^^^
File "", line 236, in makedirs
FileNotFoundError: [Errno 2] No such file or directory: ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant