From 5c9d78e5372193798ba79c1ad4ec252b785a4369 Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Wed, 4 Oct 2017 08:03:52 +0300 Subject: [PATCH] Fix missing six.text_type() call on APIException.__str__ The call was added in 426547c61c725ca7dc47671c084d1a2805c92305 to allow for dict-style arguments to ValidationError but does not apply to other APIException descendants. It is possible to hit edge cases when printing an APIException in a custom exception handler, that was passed a non-string as its first argument (eg. AuthenticationError({"code": "foo", "detail": "bar"})) --- rest_framework/exceptions.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index 12fd41931..d885ba643 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -92,7 +92,7 @@ class APIException(Exception): self.detail = _get_error_details(detail, code) def __str__(self): - return self.detail + return six.text_type(self.detail) def get_codes(self): """ @@ -136,9 +136,6 @@ class ValidationError(APIException): self.detail = _get_error_details(detail, code) - def __str__(self): - return six.text_type(self.detail) - class ParseError(APIException): status_code = status.HTTP_400_BAD_REQUEST