Opened 18 years ago

Closed 17 years ago

#4546 closed (fixed)

utils.datastructures.SortDict don't work after pop or popitem method called

Reported by: glin@… Owned by: nobody
Component: Core (Other) Version:
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

utils.datastructures.SortDict don't work after pop or popitem method called, here is example:

In [1]: from django.utils.datastructures import SortedDict

In [2]: s=SortedDict({1:2,3:4,2:3})

In [3]: s.popitem()
Out[3]: (1, 2)

In [4]: s.items()
---------------------------------------------------------------------------
exceptions.KeyError                                  Traceback (most recent call last)

/home/glin/programming/workspace/nicms/<ipython console>

/usr/lib/python2.4/site-packages/django/utils/datastructures.py in items(self)
     72
     73     def items(self):
---> 74         return zip(self.keyOrder, self.values())
     75
     76     def keys(self):

/usr/lib/python2.4/site-packages/django/utils/datastructures.py in values(self)
     78
     79     def values(self):
---> 80         return [dict.__getitem__(self, k) for k in self.keyOrder]
     81
     82     def update(self, dict):

KeyError: 1

It is because pop and popitem methods are not overriden, so items in keyOrder attribute are not deleted.

Attachments (3)

datastructures.py (8.8 KB ) - added by glin@… 18 years ago.
datastructures.py.diff (798 bytes ) - added by glin@… 18 years ago.
tests.py.diff (578 bytes ) - added by Glin <glin@…> 17 years ago.

Download all attachments as: .zip

Change History (8)

by glin@…, 18 years ago

Attachment: datastructures.py added

comment:1 by Chris Beaven, 18 years ago

Glin, could you please attach a diff instead of the whole file? Thanks.

by glin@…, 18 years ago

Attachment: datastructures.py.diff added

comment:2 by glin@…, 18 years ago

Of course, I just uploaded wrong file ;).

comment:3 by Chris Beaven, 18 years ago

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted
Version: newforms-admin

Thanks, add some tests and it'll be ready

by Glin <glin@…>, 17 years ago

Attachment: tests.py.diff added

comment:4 by Glin <glin@…>, 17 years ago

Needs tests: unset

Tests added.

comment:5 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

This was fixed as part of [6593].

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