Opened 8 years ago

Closed 7 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: UI/UX:

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

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by glin@…

comment:1 Changed 8 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

Changed 8 years ago by glin@…

comment:2 Changed 8 years ago by glin@…

Of course, I just uploaded wrong file ;).

comment:3 Changed 8 years ago by SmileyChris

  • Has patch set
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted
  • Version newforms-admin deleted

Thanks, add some tests and it'll be ready

Changed 8 years ago by Glin <glin@…>

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

  • Needs tests unset

Tests added.

comment:5 Changed 7 years ago by mtredinnick

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

This was fixed as part of [6593].

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