Skip to content

dbm.dumb.reorganize() can cause data loss after reopening #155869

Description

@lkk7

Bug report

Bug description:

Repro script:

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"

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions