import dbm.dumb
import pathlib
import tempfile
with tempfile.TemporaryDirectory() as tmpdir:
path = pathlib.Path(tmpdir) / "database"
with dbm.dumb.open(path, "n") as db:
db[b"deleted"] = b"x"
db[b"retained"] = b"value"
del db[b"deleted"]
db.reorganize()
print("before reopening:", db[b"retained"])
with dbm.dumb.open(path, "r") as db:
print("after reopening: ", db[b"retained"])
assert db[b"retained"] == b"value"
Bug report
Bug description:
Repro script:
If
reorganize()moves the value, it doesn't persist its new offset. The database works until it's closed and opened again. Then the bad offset is loaded from disk.CPython versions tested on:
CPython main branch, 3.15
Operating systems tested on:
macOS
Linked PRs
dbm.dumb.reorganize()#155872