You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to read sqlite3 database keys in read-only directory with Python 3.13 with shelve #135386
In Python 3.13, sqlite is the new default for creating databases (https://www.python.org/downloads/release/python-3130/). However, it seems that it is not possible to get the keys of the database if the database file is in a read-only folder.
The setup:
mkdir PythonTest
cd PythonTest
python -c "import shelve; shelve.open('db.db', 'c')"
cd ..
chmod 555 PythonTest
Traceback (most recent call last):
File "/usr/lib/python3.13/dbm/sqlite3.py", line 79, in _execute
return closing(self._cx.execute(*args, **kwargs))
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: attempt to write a readonly database
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/read.py", line 5, in <module>
print(list(db.keys()))
~~~~^^^^^^^^^^^
File "<frozen _collections_abc>", line 854, in __len__
File "/usr/lib/python3.13/shelve.py", line 99, in __len__
return len(self.dict)
File "/usr/lib/python3.13/dbm/sqlite3.py", line 84, in __len__
with self._execute(GET_SIZE) as cu:
~~~~~~~~~~~~~^^^^^^^^^^
File "/usr/lib/python3.13/dbm/sqlite3.py", line 81, in _execute
raise error(str(exc))
dbm.sqlite3.error: attempt to write a readonly database
Hi,
Thanks for reporting this issue! I have worked on a fix that adds the immutable=1 flag when opening a read-only SQLite DB to avoid WAL/SHM file errors.
I am preparing a PR #135566 and will submit it soon for review.
Looking forward to feedback from the maintainers and community.
Activity
vstinner commentedon Jun 11, 2025
cc @erlend-aasland
GeneralK1ng commentedon Jun 16, 2025
Hi,
Thanks for reporting this issue! I have worked on a fix that adds the immutable=1 flag when opening a read-only SQLite DB to avoid WAL/SHM file errors.
I am preparing a PR #135566 and will submit it soon for review.
Looking forward to feedback from the maintainers and community.
Thanks!
pythongh-135386: Fix dbm.sqlite3 readonly open error by using immutab…
pythongh-135386: Fix dbm.sqlite3 readonly open error by using immutab…
pythongh-135386: Fix dbm.sqlite3 readonly open error by using immutab…
gh-135386: Fix "unable to open database file" errors on readonly DB (G…
pythongh-135386: Fix "unable to open database file" errors on readonl…
pythongh-135386: Fix "unable to open database file" errors on readonl…
[3.13] gh-135386: Fix "unable to open database file" errors on readon…
pythongh-135386: Skip readonly tests for the root user
pythongh-135386: Fix "unable to open database file" errors on readonl…
gh-135386: Skip readonly tests for the root user (GH-138058)
pythongh-135386: Skip readonly tests for the root user (pythonGH-138058)
[3.13] gh-135386: Skip readonly tests for the root user (GH-138058) (G…
[3.14] gh-135386: Fix "unable to open database file" errors on readon…
spiral-fitting: date CPython's immutable=1 to 3.13.8 and 3.14.1