Skip to content

Commit

Permalink
Fixed #19262 -- Support cookie pickling in SimpleTemplateResponse
Browse files Browse the repository at this point in the history
Refs #15863.
  • Loading branch information
seanbrant authored and claudep committed Nov 9, 2012
1 parent 1b307d6 commit 4d817b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/template/response.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __getstate__(self):
rendered, and that the pickled state only includes rendered rendered, and that the pickled state only includes rendered
data, not the data used to construct the response. 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: if not self._is_rendered:
raise ContentNotRenderedError('The response content must be ' raise ContentNotRenderedError('The response content must be '
'rendered before it can be pickled.') 'rendered before it can be pickled.')
Expand Down
15 changes: 15 additions & 0 deletions tests/regressiontests/templates/response.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ def test_repickling(self):
unpickled_response = pickle.loads(pickled_response) unpickled_response = pickle.loads(pickled_response)
repickled_response = pickle.dumps(unpickled_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( @override_settings(
TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name], TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name],
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')), TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')),
Expand Down

0 comments on commit 4d817b3

Please sign in to comment.