From 000938c16a137f8e51cc649be5b2b8d2bd199613 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Fri, 22 Nov 2024 15:38:40 -0300 Subject: [PATCH] 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] https://github.com/python-websockets/websockets/commit/7c8e0b9d6246cd7bdd304f630f719fc55620f89a --- juju/client/connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/juju/client/connection.py b/juju/client/connection.py index 88c31c2ab..ea285a14c 100644 --- a/juju/client/connection.py +++ b/juju/client/connection.py @@ -17,6 +17,7 @@ import websockets from dateutil.parser import parse from typing_extensions import Self, TypeAlias, overload +from websockets.protocol import State from juju import errors, jasyncio, tag, utils from juju.client import client @@ -92,7 +93,7 @@ def status(self): and connection._receiver_task.cancelled() ) - if stopped or not connection._ws.open: + if stopped or connection._ws.state is not State.OPEN: return self.ERROR # everything is fine! @@ -357,8 +358,7 @@ async def close(self, to_reconnect: bool = False): tasks_need_to_be_gathered.append(self._debug_log_task) self._debug_log_task.cancel() - if self._ws and not self._ws.closed: - await self._ws.close() + await self._ws.close() if not to_reconnect: try: