From 2ebd4797595fb86504cf093fe8ed94c59a061acb Mon Sep 17 00:00:00 2001 From: Craig Anderson Date: Fri, 20 Apr 2018 14:32:37 +0100 Subject: [PATCH] Allow hashing of ErrorDetail to fix #5919 (#5932) --- rest_framework/exceptions.py | 3 +++ tests/test_exceptions.py | 4 ++++ 2 files changed, 7 insertions(+) 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):