-
-
Notifications
You must be signed in to change notification settings - Fork 351
Closed
Description
Issue
I seem to be unable to pass arguments, such as auto_reconnect
to the AsyncRealtimeClient
. Therefore, I need to patch the client after initialization.
client = await acreate_client(settings.SUPABASE_URL, settings.SUPABASE_SERVICE_ROLE_SECRET)
client.realtime = AsyncRealtimeClient(client.realtime_url, token=client.supabase_key, auto_reconnect=True)
return client
The problem
The acreate_client
accepts ClientOptions
, which has a realtime
field with type Optional[Dict[str, Any]]
. These will be passed to _init_realtime_client
.
supabase-py/supabase/_async/client.py
Lines 84 to 88 in bf252a2
self.realtime = self._init_realtime_client( | |
realtime_url=self.realtime_url, | |
supabase_key=self.supabase_key, | |
options=options.realtime if options else None, | |
) |
supabase-py/supabase/_async/client.py
Lines 218 to 225 in bf252a2
@staticmethod | |
def _init_realtime_client( | |
realtime_url: str, supabase_key: str, options: Optional[Dict[str, Any]] | |
) -> AsyncRealtimeClient: | |
"""Private method for creating an instance of the realtime-py client.""" | |
return AsyncRealtimeClient( | |
realtime_url, token=supabase_key, params=options or {} | |
) |
However, the options are passed to params, and I cannot pass the auto_reconnect flag (or other attributes) via the supabase module.
class AsyncRealtimeClient:
def __init__(
self,
url: str,
token: str,
auto_reconnect: bool = False,
params: Dict[str, Any] = {},
hb_interval: int = 30,
max_retries: int = 5,
initial_backoff: float = 1.0,
) -> None:
Suggestion
@staticmethod
def _init_realtime_client(
realtime_url: str, supabase_key: str, options: Optional[Dict[str, Any]] = None
) -> AsyncRealtimeClient:
"""Private method for creating an instance of the realtime-py client."""
if options is None:
options = {}
return AsyncRealtimeClient(
realtime_url, token=supabase_key, **options
)
Unpack options
immediately. This would allow configuration such as:
options = ClientOptions(
realtime={
"auto_reconnect": True,
}
)
client = await acreate_client(settings.SUPABASE_URL, settings.SUPABASE_SERVICE_ROLE_SECRET, options)
Metadata
Metadata
Assignees
Labels
No labels