diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index 3c64386da..f79b16129 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -91,6 +91,9 @@ class ErrorDetail(six.text_type): self.code, )) + def __hash__(self): + return hash(str(self)) + class APIException(Exception): """ diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 0c5ff7aae..ce0ed8514 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -81,6 +81,10 @@ class ErrorDetailTests(TestCase): assert str(ErrorDetail('msg1')) == 'msg1' assert str(ErrorDetail('msg1', 'code')) == 'msg1' + def test_hash(self): + assert hash(ErrorDetail('msg')) == hash('msg') + assert hash(ErrorDetail('msg', 'code')) == hash('msg') + class TranslationTests(TestCase):