-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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?
Changes from 6 commits
761f178
3e3a3ba
7f988dd
775683e
66899ff
4561075
7c40be3
759f218
73d9e24
c4c8065
b586fc3
bd405f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import stat | ||
import os | ||
import sys | ||
import unittest | ||
from contextlib import closing | ||
|
@@ -89,6 +91,29 @@ def test_readonly_keys(self): | |
def test_readonly_iter(self): | ||
self.assertEqual([k for k in self.db], [b"key1", b"key2"]) | ||
|
||
def test_readonly_open_without_wal_shm(self): | ||
wal_path = self.filename + "-wal" | ||
shm_path = self.filename + "-shm" | ||
|
||
for suffix in wal_path, shm_path: | ||
os_helper.unlink(suffix) | ||
|
||
try: | ||
self.db.close() | ||
except Exception: | ||
pass | ||
|
||
os.chmod(self.filename, stat.S_IREAD) | ||
|
||
db = dbm_sqlite3.open(self.filename, "r") | ||
try: | ||
self.assertEqual(db[b"key1"], b"value1") | ||
self.assertEqual(db[b"key2"], b"value2") | ||
finally: | ||
db.close() | ||
|
||
GeneralK1ng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
os.chmod(self.filename, stat.S_IWRITE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC correctly, this change makes it so that the WAL/SHM files are no longer created in read-only mode? In that case, we could simplify the test to simply open the database in read-only mode and check that the auxiliary files are not written. I'm thinking something like this: class Immutable(unittest.TestCase):
def setUp(self):
self.filename = os_helper.TESTFN
self.db = dbm_sqlite3.open(self.filename, "r")
def tearDown(self):
self.db.close()
def test_readonly_open_without_wal_shm(self):
wal_path = self.filename + "-wal"
shm_path = self.filename + "-shm"
self.assertFalse(os.path.exists(wal_path))
self.assertFalse(os.path.exists(shm_path)) Or does this also affect the database file itself? i.e. does passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I’ve replaced the original test with your suggested version in a new Immutable test class. It’s much cleaner and focused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, exactly — without Passing |
||
|
||
|
||
class ReadWrite(_SQLiteDbmTests): | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix :exc:`sqlite3.OperationalError` error when using :func:`dbm.open` with a read-only file object. |
Uh oh!
There was an error while loading. Please reload this page.