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

OrderedDict iterators are exhausted during pickling #78755

Closed
sir-sigurd mannequin opened this issue Sep 4, 2018 · 7 comments
Closed

OrderedDict iterators are exhausted during pickling #78755

sir-sigurd mannequin opened this issue Sep 4, 2018 · 7 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@sir-sigurd
Copy link
Mannequin

sir-sigurd mannequin commented Sep 4, 2018

BPO 34574
Nosy @serhiy-storchaka, @MojoVampire, @sir-sigurd, @miss-islington, @tirkarthi
PRs
  • bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. #9051
  • [3.7] bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. (GH-9051) #9996
  • [3.6] bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. (GH-9051) #9997
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2018-10-20.06:06:46.626>
    created_at = <Date 2018-09-04.04:19:39.374>
    labels = ['extension-modules', '3.8', 'type-bug', '3.7']
    title = 'OrderedDict iterators are exhausted during pickling'
    updated_at = <Date 2018-10-20.06:06:46.548>
    user = 'https://github.com/sir-sigurd'

    bugs.python.org fields:

    activity = <Date 2018-10-20.06:06:46.548>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2018-10-20.06:06:46.626>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2018-09-04.04:19:39.374>
    creator = 'sir-sigurd'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34574
    keywords = ['patch']
    message_count = 7.0
    messages = ['324551', '324650', '324664', '328124', '328126', '328127', '328128']
    nosy_count = 5.0
    nosy_names = ['serhiy.storchaka', 'josh.r', 'sir-sigurd', 'miss-islington', 'xtreak']
    pr_nums = ['9051', '9996', '9997']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34574'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @sir-sigurd
    Copy link
    Mannequin Author

    sir-sigurd mannequin commented Sep 4, 2018

    In [1]: from collections import OrderedDict

    In [2]: od = OrderedDict.fromkeys(range(10))

    In [3]: it = iter(od)

    In [4]: it.__reduce__()
    Out[4]: (<function iter>, ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],))

    In [5]: list(it)
    Out[5]: []

    @sir-sigurd sir-sigurd mannequin added the type-bug An unexpected behavior, bug, or error label Sep 4, 2018
    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Sep 5, 2018

    This would presumably be a side-effect of all generic pickling operations of iterators; figuring out what the iterator produces requires running out the iterator. You could special case it case-by-case, but that just makes the behavior unreliable/confusing; now some iterators pickle without being mutated, and others don't. Do you have a proposal to fix it? Is it something that needs to be fixed at all, when the option to pickle the original OrderedDict directly is there?

    @sir-sigurd
    Copy link
    Mannequin Author

    sir-sigurd mannequin commented Sep 6, 2018

    Other iterators either don't support pickling or aren't mutated during pickling:

    In [10]: it = iter({1})

    In [11]: pickle.dumps(it)
    Out[11]: b'\x80\x04\x95\x1e\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94]\x94K\x01a\x85\x94R\x94.'

    In [12]: list(it)
    Out[12]: [1]

    In [13]: it = (x for x in {1})

    In [14]: pickle.dumps(it)
    ---------------------------------------------------------------------------

    TypeError                                 Traceback (most recent call last)
    <ipython-input-14-7e86a183a31c> in <module>()
    ----> 1 pickle.dumps(it)

    TypeError: can't pickle generator objects

    @serhiy-storchaka serhiy-storchaka self-assigned this Sep 8, 2018
    @serhiy-storchaka
    Copy link
    Member

    New changeset a5259fb by Serhiy Storchaka (Sergey Fedoseev) in branch 'master':
    bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. (GH-9051)
    a5259fb

    @miss-islington
    Copy link
    Contributor

    New changeset dcd56f6 by Miss Islington (bot) in branch '3.7':
    bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. (GH-9051)
    dcd56f6

    @miss-islington
    Copy link
    Contributor

    New changeset 0d3dd9f by Miss Islington (bot) in branch '3.6':
    bpo-34574: Prevent OrderedDict iterators from exhaustion during pickling. (GH-9051)
    0d3dd9f

    @serhiy-storchaka
    Copy link
    Member

    Thank your Sergey for your report and fix.

    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir 3.7 (EOL) end of life 3.8 only security fixes labels Oct 20, 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.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants