-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Closed
Closed
Copy link
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
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
Then running
import shelve
with shelve.open('PythonTest/db.db', 'r') as db:
print(list(db.keys()))will fail with
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
which I believe to be unexpected since the database was opened with the r flag, for read-only (see https://docs.python.org/3/library/dbm.html#dbm.open).
CPython versions tested on:
3.13.2 and 3.13.3
Operating systems tested on:
Linux (Ubuntu 24, Arch Linux)
Linked PRs
- gh-135386: Fix "unable to open database file" errors on readonly DB #135566
- [3.14] gh-135386: Fix "unable to open database file" errors on readonly DB (GH-135566) #138056
- [3.13] gh-135386: Fix "unable to open database file" errors on readonly DB (GH-135566) #138057
- gh-135386: Skip readonly tests for the root user #138058
- [3.13] gh-135386: Skip readonly tests for the root user (GH-138058) #138064
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done
Status
Done