From 4769db6b5fddaed93a8d8d03d0c36f7262e9ac8b Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 26 Apr 2013 08:57:39 +0200 Subject: [PATCH] Fixed #20321 -- Added missing key name in MergeDict KeyError message Thanks mark.harviston et gmail.com for the report. --- django/utils/datastructures.py | 2 +- tests/utils_tests/test_datastructures.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index b3060202be..a211323320 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -26,7 +26,7 @@ class MergeDict(object): return dict_[key] except KeyError: pass - raise KeyError + raise KeyError(key) def __copy__(self): return self.__class__(*self.dicts) diff --git a/tests/utils_tests/test_datastructures.py b/tests/utils_tests/test_datastructures.py index 91111cc2ed..5829e7c2d7 100644 --- a/tests/utils_tests/test_datastructures.py +++ b/tests/utils_tests/test_datastructures.py @@ -209,6 +209,14 @@ class MergeDictTests(SimpleTestCase): self.assertFalse(empty) self.assertTrue(not_empty) + def test_key_error(self): + """ + Test that the message of KeyError contains the missing key name. + """ + d1 = MergeDict({'key1': 42}) + with six.assertRaisesRegex(self, KeyError, 'key2'): + d1['key2'] + class MultiValueDictTests(SimpleTestCase):