Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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 authored November 09, 2012 claudep committed November 09, 2012
2  django/template/response.py
@@ -40,7 +40,7 @@ def __getstate__(self):
40 40
         rendered, and that the pickled state only includes rendered
41 41
         data, not the data used to construct the response.
42 42
         """
43  
-        obj_dict = self.__dict__.copy()
  43
+        obj_dict = super(SimpleTemplateResponse, self).__getstate__()
44 44
         if not self._is_rendered:
45 45
             raise ContentNotRenderedError('The response content must be '
46 46
                                           'rendered before it can be pickled.')
15  tests/regressiontests/templates/response.py
@@ -189,6 +189,21 @@ def test_repickling(self):
189 189
         unpickled_response = pickle.loads(pickled_response)
190 190
         repickled_response = pickle.dumps(unpickled_response)
191 191
 
  192
+    def test_pickling_cookie(self):
  193
+        response = SimpleTemplateResponse('first/test.html', {
  194
+                'value': 123,
  195
+                'fn': datetime.now,
  196
+            })
  197
+
  198
+        response.cookies['key'] = 'value'
  199
+
  200
+        response.render()
  201
+        pickled_response = pickle.dumps(response, pickle.HIGHEST_PROTOCOL)
  202
+        unpickled_response = pickle.loads(pickled_response)
  203
+
  204
+        self.assertEqual(unpickled_response.cookies['key'].value, 'value')
  205
+
  206
+
192 207
 @override_settings(
193 208
     TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name],
194 209
     TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')),

0 notes on commit 6554137

Please sign in to comment.
Something went wrong with that request. Please try again.