From e7b2ad8020aef2941eb477632c4a453e7150202a Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 18 Feb 2008 23:08:51 +0000 Subject: [PATCH] Fixed #6611 -- When copying a SortedDict, make a new copy of the keys list. Thanks, Jeremy Dunck. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7129 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/datastructures.py | 2 +- tests/regressiontests/datastructures/tests.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index f46b57c151..a2b78a31c5 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -145,7 +145,7 @@ class SortedDict(dict): """Returns a copy of this object.""" # This way of initializing the copy means it works for subclasses, too. obj = self.__class__(self) - obj.keyOrder = self.keyOrder + obj.keyOrder = self.keyOrder[:] return obj def __repr__(self): diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py index b5dc5d171b..172057f080 100644 --- a/tests/regressiontests/datastructures/tests.py +++ b/tests/regressiontests/datastructures/tests.py @@ -77,6 +77,8 @@ MultiValueDictKeyError: "Key 'lastname' not found in >> d.keys() == d.copy().keys() True +>>> d2 = d.copy() +>>> d2['four'] = 'four' >>> print repr(d) {'one': 'not one', 'two': 'two', 'three': 'three'} >>> d.pop('one', 'missing')