Skip to content
Myr

fix contextlib.closing bug for sessions where content is not consumed (issue #2593)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by colin · committed by colin · parent 3c850b3 · Browse files · 3 files+14 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+14 added−0 removed

  • other:+14 added−0 removed

3 files+14 added−0 removed

modified:requests/models.py+3 added
840 unmodified lines
841 called the underlying ``raw`` object must not be accessed again.842843 *Note: Should not normally need to be called explicitly.*844 """845 if not self._content_consumed:846 return self.raw.close()847848 return self.raw.release_conn()
modified:AUTHORS.rst+1 added
156 unmodified lines
157- Arthur Darcet (`@arthurdarcet <https://github.com/arthurdarcet>`_)158- Ulrich Petri (`@ulope <https://github.com/ulope>`_)159- Muhammad Yasoob Ullah Khalid <yasoob.khld@gmail.com> (`@yasoob <https://github.com/yasoob>`_)160- Paul van der Linden (`@pvanderlinden <https://github.com/pvanderlinden>`_)161- Colin Dickson (`@colindickson <https://github.com/colindickson>`_)
modified:test_requests.py+10 added
7 unmodified lines
8import os9import pickle10import unittest11import collections12import contextlib1314import io15import requests16import pytest
1043 unmodified lines
1060 it = r.iter_lines()1061 next(it)1062 assert len(list(it)) == 310631064 def test_unconsumed_session_response_closes_connection(self):1065 s = requests.session()10661067 with contextlib.closing(s.get(httpbin('stream/4'), stream=True)) as response:1068 pass10691070 self.assertEqual(response._content_consumed, False)1071 self.assertTrue(response.raw.closed, True)10721073 @pytest.mark.xfail1074 def test_response_iter_lines_reentrant(self):1075 """Response.iter_lines() is not reentrant safe"""1076 r = requests.get(httpbin('stream/4'), stream=True)
572 unmodified lines