Skip to content

Commit

Permalink
Drop use of Monitor._ws.open and Connection._ws.closed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
freyes committed Nov 22, 2024
1 parent f176d82 commit b2ac376
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions juju/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -357,7 +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:
if self._ws and self._ws.state is not State.CLOSED:
await self._ws.close()

if not to_reconnect:
Expand Down

0 comments on commit b2ac376

Please sign in to comment.