Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ Every filter on the table counts, including `match()`, `in_()`, `or_()` and a ne

`heartbeat_interval` and `heartbeat_timeout` are typed `float` and are in seconds. `connect_once`, `RealtimeClient` and `RealtimeClientOptions` raise `ValueError` when either one is not positive.

## Realtime `close()` is `aclose()`

`RealtimeClient.close()` is renamed to `aclose()`, the name Python uses for an async close, so `contextlib.aclosing(client)` works. `close()` is removed.

## Auth `persist_session` is removed and `storage_key` takes effect

`AsyncSupabaseAuthClient` and `SyncSupabaseAuthClient` no longer take `persist_session`. It was never passed on to the session manager, so it had no effect. To keep the session only in memory, leave `storage` out. Each client then gets its own memory storage, so clients created per request do not share a session.
Expand Down
2 changes: 1 addition & 1 deletion sdk-compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ features:
realtime.client.disconnect:
status: implemented
symbols:
- RealtimeClient.close
- RealtimeClient.aclose
realtime.client.get_channels:
status: implemented
symbols:
Expand Down
10 changes: 2 additions & 8 deletions src/realtime/src/realtime/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def __aexit__(
assert self.heartbeat_task, "Connection should never exit without hearbeat_task"
self.heartbeat_task.cancel()
assert self.client, "Connection should never exit without client"
await self.client.close()
await self.client.aclose()


MAX_RECONNECT_DELAY = 60
Expand Down Expand Up @@ -216,15 +216,9 @@ async def listen(self) -> None:
):
self._connection_failure.set_exception(exc)

async def close(self) -> None:
async def aclose(self) -> None:
"""
Close the WebSocket connection.

Returns:
None

Raises:
NotConnectedError: If the connection is not established when this method is called.
"""

await self._ws_connection.close()
Expand Down
26 changes: 26 additions & 0 deletions src/realtime/tests/test_close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from contextlib import aclosing
from unittest.mock import AsyncMock

from yarl import URL

from realtime import RealtimeClient

REALTIME_URL = URL("ws://127.0.0.1/realtime/v1")


async def test_aclose_closes_the_websocket() -> None:
close = AsyncMock()
client = RealtimeClient(REALTIME_URL, AsyncMock(close=close))

await client.aclose()

close.assert_awaited_once()


async def test_aclosing_closes_the_websocket() -> None:
close = AsyncMock()

async with aclosing(RealtimeClient(REALTIME_URL, AsyncMock(close=close))):
close.assert_not_awaited()

close.assert_awaited_once()
Loading