Merge ~nansari/django-piston:fix-for-SN-1445 into django-piston:master

Proposed by Najam Ahmed Ansari
Status: Merged
Approved by: Najam Ahmed Ansari
Approved revision: 32fbb4a8707d9da68f2ae9cd660b1dcd0a716bf0
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~nansari/django-piston:fix-for-SN-1445
Merge into: django-piston:master
Diff against target: 55 lines (+8/-17)
2 files modified
piston/tests.py (+3/-0)
piston/utils.py (+5/-17)
Reviewer Review Type Date Requested Status
Przemysław Suliga Approve
Review via email: mp+446176@code.launchpad.net

Commit message

Removing piston's custom HttpResponseWrapper

Description of the change

The wrapper class was attempting to work around a bug in Django which has since
been fixed, rendering the wrapper unnecessary. Removing the wrapper also fixes
SN-1445.

To post a comment you must log in.
Revision history for this message
Przemysław Suliga (suligap) wrote :

The extra json.dumps() additions you added to tests made me wonder. And I think something like

https://pastebin.canonical.com/p/T85sYPMNbN/ - diff applied to this MP

might be the way to go after all. That wrapper has an original function beyond working around an old django bug. But we can make it use django's auto encoding when needed (as in my diff).

See also a testing comment.

Revision history for this message
Najam Ahmed Ansari (nansari) wrote :

Updated based on the feedback.

Revision history for this message
Przemysław Suliga (suligap) :
Revision history for this message
Przemysław Suliga (suligap) wrote :

Thanks, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/piston/tests.py b/piston/tests.py
2index aacce0b..65ecca7 100644
3--- a/piston/tests.py
4+++ b/piston/tests.py
5@@ -187,6 +187,9 @@ class ErrorHandlerTest(TestCase):
6
7 self.assertTrue(isinstance(response, HttpResponse), "Expected a response, not: %s"
8 % response)
9+ error_str = response.content.decode('utf-8')
10+ self.assertIn('Method signature does not match', error_str,
11+ 'Expected underlying exception to be handled')
12
13
14 def test_other_error(self):
15diff --git a/piston/utils.py b/piston/utils.py
16index 8e76718..79b9903 100644
17--- a/piston/utils.py
18+++ b/piston/utils.py
19@@ -53,9 +53,7 @@ class rc_factory(object):
20
21 class HttpResponseWrapper(HttpResponse):
22 """
23- Wrap HttpResponse and make sure that the internal
24- _is_string/_base_content_is_iter flag is updated when the
25- _set_content method (via the content property) is called
26+ Wrap HttpResponse to set _use_emitter appropriately.
27 """
28 def _set_content(self, content):
29 """
30@@ -70,22 +68,12 @@ class rc_factory(object):
31 self._container = content
32 self._use_emitter = True
33 else:
34- self._container = [content]
35+ HttpResponse.content.fset(self, content)
36 self._use_emitter = False
37- # Django 1.7 and above does not have any custom internals to
38- # define the type of the content
39- if django.VERSION < (1, 7):
40- self._base_content_is_iter = self._use_emitter
41
42- if django.VERSION >= (1, 5):
43- # HttpResponse._get_content does not exists in Django >= 1.5
44-
45- @HttpResponse.content.setter
46- def content(self, content):
47- self._set_content(content)
48-
49- else:
50- content = property(HttpResponse._get_content, _set_content)
51+ @HttpResponse.content.setter
52+ def content(self, content):
53+ self._set_content(content)
54
55 return HttpResponseWrapper(r, content_type='text/plain', status=c)
56

Subscribers

People subscribed via source and target branches