Skip to content

[Bug?] Add option for read-only #136

@roniemartinez

Description

@roniemartinez

Hi,

I recently used TinyDB and added it (including the pre-processed JSON data file) to my PyPI package. Everything works fine but not on systems with lower permissions - READ-ONLY.

[Mon May 22 06:42:14.710192 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]   File "/opt/python/run/venv/lib/python3.4/site-packages/tinydb/database.py", line 86, in __init__
[Mon May 22 06:42:14.710196 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]     self._storage = storage(*args, **kwargs)
[Mon May 22 06:42:14.710213 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]   File "/opt/python/run/venv/lib/python3.4/site-packages/tinydb/middlewares.py", line 63, in __call__
[Mon May 22 06:42:14.710217 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]     self.storage = self._storage_cls(*args, **kwargs)
[Mon May 22 06:42:14.710234 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]   File "/opt/python/run/venv/lib/python3.4/site-packages/tinydb/storages.py", line 88, in __init__
[Mon May 22 06:42:14.710248 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]     touch(path, create_dirs=create_dirs)  # Create file if not exists
[Mon May 22 06:42:14.710267 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]   File "/opt/python/run/venv/lib/python3.4/site-packages/tinydb/storages.py", line 23, in touch
[Mon May 22 06:42:14.710270 2017] [:error] [pid 5089] [remote 125.60.148.241:45001]     with open(fname, 'a'):
[Mon May 22 06:42:14.710294 2017] [:error] [pid 5089] [remote 125.60.148.241:45001] PermissionError: [Errno 13] Permission denied: '/opt/python/run/venv/lib/python3.4/site-packages/<filename.json>

As you can see, 'a' mode on open() function is hardcoded. The use case is only to read the file, though.

For now the quick fix is to add write permission to the required JSON file. If there is an option to modify the mode, that will be great!

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions