Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.5.x] Fixed #19262 -- Support cookie pickling in SimpleTemplateResp…

…onse

Refs #15863.
Backport of 4d817b3 from master.
  • Loading branch information...
commit 6554137eebe4bd10bdf3f1be21f63f0a9cffd7ff 1 parent dc95791
Sean Brant seanbrant authored claudep committed
2  django/template/response.py
View
@@ -40,7 +40,7 @@ def __getstate__(self):
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.')
15 tests/regressiontests/templates/response.py
View
@@ -189,6 +189,21 @@ def test_repickling(self):
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')),
Please sign in to comment.
Something went wrong with that request. Please try again.