Skip to content

Commit 79af18a

Browse files
authored
Bump httpx to 0.17.1 (home-assistant#48388)
* Bump httpx to 0.17.1 * git add * typing * add test * tweak
1 parent b50dcef commit 79af18a

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

homeassistant/helpers/httpx_client.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ def get_async_client(
3939
return client
4040

4141

42+
class HassHttpXAsyncClient(httpx.AsyncClient):
43+
"""httpx AsyncClient that suppresses context management."""
44+
45+
async def __aenter__(self: HassHttpXAsyncClient) -> HassHttpXAsyncClient:
46+
"""Prevent an integration from reopen of the client via context manager."""
47+
return self
48+
49+
async def __aexit__(self, *args: Any) -> None: # pylint: disable=signature-differs
50+
"""Prevent an integration from close of the client via context manager."""
51+
52+
4253
@callback
4354
def create_async_httpx_client(
4455
hass: HomeAssistantType,
@@ -53,7 +64,7 @@ def create_async_httpx_client(
5364
5465
This method must be run in the event loop.
5566
"""
56-
client = httpx.AsyncClient(
67+
client = HassHttpXAsyncClient(
5768
verify=verify_ssl,
5869
headers={USER_AGENT: SERVER_SOFTWARE},
5970
**kwargs,

homeassistant/package_constraints.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ distro==1.5.0
1616
emoji==1.2.0
1717
hass-nabucasa==0.42.0
1818
home-assistant-frontend==20210324.0
19-
httpx==0.16.1
19+
httpx==0.17.1
2020
jinja2>=2.11.3
2121
netdisco==2.8.2
2222
paho-mqtt==1.5.1

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ awesomeversion==21.2.3
99
bcrypt==3.1.7
1010
certifi>=2020.12.5
1111
ciso8601==2.1.3
12-
httpx==0.16.1
12+
httpx==0.17.1
1313
jinja2>=2.11.3
1414
PyJWT==1.7.1
1515
cryptography==3.3.2

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"bcrypt==3.1.7",
4141
"certifi>=2020.12.5",
4242
"ciso8601==2.1.3",
43-
"httpx==0.16.1",
43+
"httpx==0.17.1",
4444
"jinja2>=2.11.3",
4545
"PyJWT==1.7.1",
4646
# PyJWT has loose dependency. We want the latest one.

tests/helpers/test_httpx_client.py

+13
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ async def test_get_async_client_patched_close(hass):
8080
assert mock_aclose.call_count == 0
8181

8282

83+
async def test_get_async_client_context_manager(hass):
84+
"""Test using the async client with a context manager does not close the session."""
85+
86+
with patch("httpx.AsyncClient.aclose") as mock_aclose:
87+
httpx_session = client.get_async_client(hass)
88+
assert isinstance(hass.data[client.DATA_ASYNC_CLIENT], httpx.AsyncClient)
89+
90+
async with httpx_session:
91+
pass
92+
93+
assert mock_aclose.call_count == 0
94+
95+
8396
async def test_warning_close_session_integration(hass, caplog):
8497
"""Test log warning message when closing the session from integration context."""
8598
with patch(

0 commit comments

Comments
 (0)