From d95a421694ade78dbe332a7becb8fd492bd2a01c Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 6 Feb 2017 21:28:55 -0700 Subject: Test to verify that httpexc.detail may be non-str --- pyramid/tests/test_httpexceptions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index 224fa4cf0..e2d463008 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -2,6 +2,7 @@ import unittest from pyramid.compat import ( bytes_, + string_types, text_, ) @@ -364,6 +365,11 @@ class TestHTTPException(unittest.TestCase): body = list(exc(environ, start_response))[0] self.assertEqual(body, b'200 OK\n\n/La Pe\xc3\xb1a') + def test_allow_detail_non_str(self): + exc = self._makeOne(detail={'error': 'This is a test'}) + self.assertIsInstance(exc.__str__(), string_types) + + class TestRenderAllExceptionsWithoutArguments(unittest.TestCase): def _doit(self, content_type): from pyramid.httpexceptions import status_map -- cgit v1.2.3 From 309e6be0e83b5ed08f954c7dd66c5e8cf959a006 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 6 Feb 2017 21:32:03 -0700 Subject: stringify self.detail in case it is not a string --- pyramid/httpexceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index a22b088c6..1f3934fdc 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -238,7 +238,7 @@ ${body}''') del self.content_length def __str__(self): - return self.detail or self.explanation + return str(self.detail) if self.detail else self.explanation def _json_formatter(self, status, body, title, environ): return {'message': body, -- cgit v1.2.3 From 564b63771ae370fafe059c5cf8e4a6bd7a1a5853 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 6 Feb 2017 21:37:52 -0700 Subject: Update CHANGES.txt for #2951 --- CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 218fea289..59a733bcd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,10 @@ Features Bug Fixes --------- +- HTTPException's accepts a detail kwarg that may be used to pass additional + details to the exception. You may now pass objects so long as they have a + valid __str__ method. See https://github.com/Pylons/pyramid/pull/2951 + Deprecations ------------ -- cgit v1.2.3