Skip to content

Commit

Permalink
Fixed #20321 -- Added missing key name in MergeDict KeyError message
Browse files Browse the repository at this point in the history
Thanks mark.harviston et gmail.com for the report.
  • Loading branch information
claudep committed Apr 26, 2013
1 parent 6bccbc0 commit 4769db6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/utils/datastructures.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __getitem__(self, key):
return dict_[key] return dict_[key]
except KeyError: except KeyError:
pass pass
raise KeyError raise KeyError(key)


def __copy__(self): def __copy__(self):
return self.__class__(*self.dicts) return self.__class__(*self.dicts)
Expand Down
8 changes: 8 additions & 0 deletions tests/utils_tests/test_datastructures.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ def test_bool_casting(self):
self.assertFalse(empty) self.assertFalse(empty)
self.assertTrue(not_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): class MultiValueDictTests(SimpleTestCase):


Expand Down

0 comments on commit 4769db6

Please sign in to comment.