diff options
| author | Sean Breant <brant.sean@gmail.com> | 2012-11-09 21:07:53 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-11-09 21:11:36 +0100 |
| commit | 6554137eebe4bd10bdf3f1be21f63f0a9cffd7ff (patch) | |
| tree | ecc3d6c5902443b9094ea98a13acf65afad06d13 | |
| parent | dc95791e61750024a610b6c5cf4d32b7325fcb51 (diff) | |
[1.5.x] Fixed #19262 -- Support cookie pickling in SimpleTemplateResponse
Refs #15863.
Backport of 4d817b3887 from master.
| -rw-r--r-- | django/template/response.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/templates/response.py | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/django/template/response.py b/django/template/response.py index 2cb44d127d..3b3b41331a 100644 --- a/django/template/response.py +++ b/django/template/response.py @@ -40,7 +40,7 @@ class SimpleTemplateResponse(HttpResponse): rendered, and that the pickled state only includes rendered data, not the data used to construct the response. """ - obj_dict = self.__dict__.copy() + obj_dict = super(SimpleTemplateResponse, self).__getstate__() if not self._is_rendered: raise ContentNotRenderedError('The response content must be ' 'rendered before it can be pickled.') diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py index 93919b95cd..a2a76a3310 100644 --- a/tests/regressiontests/templates/response.py +++ b/tests/regressiontests/templates/response.py @@ -189,6 +189,21 @@ class SimpleTemplateResponseTest(TestCase): unpickled_response = pickle.loads(pickled_response) repickled_response = pickle.dumps(unpickled_response) + def test_pickling_cookie(self): + response = SimpleTemplateResponse('first/test.html', { + 'value': 123, + 'fn': datetime.now, + }) + + response.cookies['key'] = 'value' + + response.render() + pickled_response = pickle.dumps(response, pickle.HIGHEST_PROTOCOL) + unpickled_response = pickle.loads(pickled_response) + + self.assertEqual(unpickled_response.cookies['key'].value, 'value') + + @override_settings( TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name], TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')), |
