+30 −5
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
What
This PR adds the SQLite URI parameter
immutable=1
when opening a database in read-only mode inLib/dbm/sqlite3.py
. This explicitly informs SQLite that the database is read-only and avoids attempts to create or write to auxiliary WAL/SHM files.Why
Without this flag, opening a read-only SQLite database may fail with errors such as "unable to open database file" when the WAL or SHM files cannot be created due to filesystem permissions or other restrictions. This is especially common when the database file is read-only and the environment prevents creation of additional files.
Adding
immutable=1
allows SQLite to operate correctly without needing to create WAL/SHM files, thus preventing these errors.Where
The change is made in the
_Database.__init__
constructor inLib/dbm/sqlite3.py
. The URI used to open the database connection is appended with&immutable=1
only if theflag
is"ro"
(read-only).Related issue
#135386
This is my first contribution to CPython. I appreciate the opportunity and look forward to feedback from the community. Thank you!