Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@claudep claudep authored
View
2  django/utils/datastructures.py
@@ -26,7 +26,7 @@ def __getitem__(self, key):
return dict_[key]
except KeyError:
pass
- raise KeyError
+ raise KeyError(key)
def __copy__(self):
return self.__class__(*self.dicts)
View
8 tests/utils_tests/test_datastructures.py
@@ -209,6 +209,14 @@ def test_bool_casting(self):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.