Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20321 -- Added missing key name in MergeDict KeyError message

Thanks mark.harviston et gmail.com for the report.
  • Loading branch information...
commit 4769db6b5fddaed93a8d8d03d0c36f7262e9ac8b 1 parent 6bccbc0
Claude Paroz authored April 26, 2013
2  django/utils/datastructures.py
@@ -26,7 +26,7 @@ def __getitem__(self, key):
26 26
                 return dict_[key]
27 27
             except KeyError:
28 28
                 pass
29  
-        raise KeyError
  29
+        raise KeyError(key)
30 30
 
31 31
     def __copy__(self):
32 32
         return self.__class__(*self.dicts)
8  tests/utils_tests/test_datastructures.py
@@ -209,6 +209,14 @@ def test_bool_casting(self):
209 209
         self.assertFalse(empty)
210 210
         self.assertTrue(not_empty)
211 211
 
  212
+    def test_key_error(self):
  213
+        """
  214
+        Test that the message of KeyError contains the missing key name.
  215
+        """
  216
+        d1 = MergeDict({'key1': 42})
  217
+        with six.assertRaisesRegex(self, KeyError, 'key2'):
  218
+            d1['key2']
  219
+
212 220
 
213 221
 class MultiValueDictTests(SimpleTestCase):
214 222
 

0 notes on commit 4769db6

Please sign in to comment.
Something went wrong with that request. Please try again.