Skip to content
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

Deleting a key in a read-only gdbm results in KeyError, not gdbm.error #77287

Closed
sam-s mannequin opened this issue Mar 19, 2018 · 5 comments
Closed

Deleting a key in a read-only gdbm results in KeyError, not gdbm.error #77287

sam-s mannequin opened this issue Mar 19, 2018 · 5 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@sam-s
Copy link
Mannequin

sam-s mannequin commented Mar 19, 2018

BPO 33106
Nosy @zhangyangyu, @sam-s
PRs
  • bpo-33106: change dbm key deletion error for readonly file from KeyError to dbm.error #6295
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-12-12.13:05:50.142>
    created_at = <Date 2018-03-19.21:44:11.062>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Deleting a key in a read-only gdbm results in KeyError, not gdbm.error'
    updated_at = <Date 2018-12-12.13:05:50.141>
    user = 'https://github.com/sam-s'

    bugs.python.org fields:

    activity = <Date 2018-12-12.13:05:50.141>
    actor = 'xiang.zhang'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-12.13:05:50.142>
    closer = 'xiang.zhang'
    components = ['Library (Lib)']
    creation = <Date 2018-03-19.21:44:11.062>
    creator = 'sam-s'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33106
    keywords = ['patch']
    message_count = 5.0
    messages = ['314119', '314120', '314603', '319062', '331694']
    nosy_count = 2.0
    nosy_names = ['xiang.zhang', 'sam-s']
    pr_nums = ['6295']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue33106'
    versions = ['Python 3.8']

    @sam-s
    Copy link
    Mannequin Author

    sam-s mannequin commented Mar 19, 2018

    deleting a key from a read-only gdbm should be gdbm.error, not KeyError:

    >>> import gdbm
    >>> db = gdbm.open("foo","n")   # create new
    >>> db["a"] = "b"
    >>> db.close()
    >>> db = gdbm.open("foo","r")   # read only
    >>> db["x"] = "1"
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    gdbm.error: Reader can't store    # correct
    >>> db["a"]
    'b'
    >>> del db["a"]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyError: 'a'    # WRONG!  should be the same as above

    @sam-s sam-s mannequin added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Mar 19, 2018
    @sam-s
    Copy link
    Mannequin Author

    sam-s mannequin commented Mar 19, 2018

    Same problem with 3.6.4, start with

    >> from dbm import gnu as gdbm

    then the same incorrect behavior

    @zhangyangyu
    Copy link
    Member

    I like this idea. But this is a behavior change so I think it could only be applied to master branch. But there is a problem, except dbm.gnu and dbm.ndbm, we also get dbm.dumb. It already raises a ValueError when deleting a key in readonly mode. Does it need to be changed to raise dbm.dumb.error to achieve consistency?

    @zhangyangyu zhangyangyu added the 3.8 only security fixes label Mar 28, 2018
    @sam-s
    Copy link
    Mannequin Author

    sam-s mannequin commented Jun 8, 2018

    I think consistency would be nice -- so, yes, dbm.dumb.error instead of ValueError (or at least a subtype of dbm.dumb.error).
    Thanks!

    @zhangyangyu
    Copy link
    Member

    New changeset 4fb0b8b by Xiang Zhang in branch 'master':
    bpo-33106: change dbm key deletion error for readonly file from KeyError to dbm.error (bpo-6295)
    4fb0b8b

    @zhangyangyu zhangyangyu added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Dec 12, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant