Opened 9 years ago

Closed 9 years ago

#6611 closed (fixed)

SortedDict.copy breaks original dict if keys are added to copy

Reported by: jdunck Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Original problem:

>>> orig = SortedDict(data={"blah": 1, "huh": 2})
>>> orig
{'blah': 1, 'huh': 2}
>>> copy = orig.copy()
>>> copy["new_key"] = 3
>>> orig
<type 'exceptions.KeyError'>: 'new_key'

Attachments (1)

sorteddict-copy-7121.diff (980 bytes) - added by jdunck 9 years ago.

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by jdunck

comment:1 Changed 9 years ago by jdunck

The basic problem is that keyOrder is shared between the two dictionaries and adding keys to the copied dictionary make iteration of the original dictionary fail because keyOrder is extended without a corresponding entry being made in the original dictionary.

comment:2 Changed 9 years ago by Simon Greenhill <dev@…>

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:3 Changed 9 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [7129]) Fixed #6611 -- When copying a SortedDict, make a new copy of the keys list.
Thanks, Jeremy Dunck.

Note: See TracTickets for help on using tickets.
Back to Top