Skip to content

Commit 8040de5

Browse files
freyesdimaqq
authored andcommitted
fix: use newer websockets API to check that connection is open
The websockets library has dropped the properties "open" and "closed" since websockets-13.0[0], this patch makes the changes needed to check for the connection's state as suggested by the documentation. [0] python-websockets/websockets@7c8e0b9
1 parent c452b66 commit 8040de5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

juju/client/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import websockets
1818
from dateutil.parser import parse
1919
from typing_extensions import Self, TypeAlias, overload
20+
from websockets.protocol import State
2021

2122
from juju import errors, jasyncio, tag, utils
2223
from juju.client import client
@@ -92,7 +93,7 @@ def status(self):
9293
and connection._receiver_task.cancelled()
9394
)
9495

95-
if stopped or not connection._ws.open:
96+
if stopped or connection._ws.state is not State.OPEN:
9697
return self.ERROR
9798

9899
# everything is fine!
@@ -357,8 +358,7 @@ async def close(self, to_reconnect: bool = False):
357358
tasks_need_to_be_gathered.append(self._debug_log_task)
358359
self._debug_log_task.cancel()
359360

360-
if self._ws and not self._ws.closed:
361-
await self._ws.close()
361+
await self._ws.close()
362362

363363
if not to_reconnect:
364364
try:

0 commit comments

Comments
 (0)