Opened 16 years ago

Closed 15 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@… 16 years ago.
datastructures.py.diff (798 bytes) - added by glin@… 16 years ago.
tests.py.diff (578 bytes) - added by Glin <glin@…> 16 years ago.

Download all attachments as: .zip

Change History (8)

Changed 16 years ago by glin@…

Attachment: datastructures.py added

comment:1 Changed 16 years ago by Chris Beaven

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

Changed 16 years ago by glin@…

Attachment: datastructures.py.diff added

comment:2 Changed 16 years ago by glin@…

Of course, I just uploaded wrong file ;).

comment:3 Changed 16 years ago by Chris Beaven

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

Thanks, add some tests and it'll be ready

Changed 16 years ago by Glin <glin@…>

Attachment: tests.py.diff added

comment:4 Changed 16 years ago by Glin <glin@…>

Needs tests: unset

Tests added.

comment:5 Changed 15 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

This was fixed as part of [6593].

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