-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135386: Fix "unable to open database file" errors on readonly DB #135566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…M errors on readonly DB
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test case. You can refer to the devguide for how to do that.
Misc/NEWS.d/next/Library/2025-06-16-15-00-13.gh-issue-135386.lNrxLc.rst
Outdated
Show resolved
Hide resolved
707f4a3
to
779faf2
Compare
779faf2
to
3e3a3ba
Compare
No need to force-push, we squash at the end. |
Got it, thanks for the reminder! |
FYI, tests are failing on Windows. |
Thanks for the suggestion. I've skipped the test on Windows using |
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!