Code

Opened 6 years ago

Closed 6 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:

Description

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 6 years ago.

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by jdunck

comment:1 Changed 6 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 6 years ago by Simon Greenhill <dev@…>

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:3 Changed 6 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.