Navigation Menu

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

copy.copy corrupts objects that return false value from __getstate__ #52096

Closed
alga mannequin opened this issue Feb 3, 2010 · 2 comments
Closed

copy.copy corrupts objects that return false value from __getstate__ #52096

alga mannequin opened this issue Feb 3, 2010 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@alga
Copy link
Mannequin

alga mannequin commented Feb 3, 2010

BPO 7848
Nosy @avassalotti
Superseder
  • bpo-6827: deepcopy erroneously doesn't call setstate if getstate returns empty dict
  • 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 2010-02-07.09:33:11.212>
    created_at = <Date 2010-02-03.18:18:43.508>
    labels = ['type-bug', 'library']
    title = 'copy.copy corrupts objects that return false value from __getstate__'
    updated_at = <Date 2010-02-07.09:33:11.212>
    user = 'https://bugs.python.org/alga'

    bugs.python.org fields:

    activity = <Date 2010-02-07.09:33:11.212>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-02-07.09:33:11.212>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2010-02-03.18:18:43.508>
    creator = 'alga'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 7848
    keywords = []
    message_count = 2.0
    messages = ['98793', '98822']
    nosy_count = 2.0
    nosy_names = ['alexandre.vassalotti', 'alga']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '6827'
    type = 'behavior'
    url = 'https://bugs.python.org/issue7848'
    versions = ['Python 2.6', 'Python 2.5', 'Python 3.1']

    @alga
    Copy link
    Mannequin Author

    alga mannequin commented Feb 3, 2010

    When copy.copy is used on an object whose __getstate__ returns 0, it can produce a corrupt copy of an object:

    >>> import copy
    >>> class Foo(object):
    ...     def __init__(self):
    ...        self.value = 0
    ...     def __getstate__(self):
    ...        return self.value
    ...     def __setstate__(self, v):
    ...        self.value = v
    ... 
    >>> one = Foo()
    >>> two = copy.copy(one)
    >>> two.value
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'Foo' object has no attribute 'value'

    Pickling/unpickling works fine for this object, so this appears to be a bug in copy._reconstruct.

    This is not a contrived example, BTrees.Length.Length from ZODB uses such a __getstate__.

    @alga alga mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 3, 2010
    @alga
    Copy link
    Mannequin Author

    alga mannequin commented Feb 4, 2010

    This bug is a duplicate of bpo-6827, sorry.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant