Skip to content

Commit fff264f

Browse files
authored
Merge pull request #236 from mohnish7/pr/234
Continuation of Pr/234: ran isort and black for tests
2 parents d01a456 + 754bc06 commit fff264f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

supabase/client.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from typing import Any, Dict
1+
from typing import Any, Dict, Union
22

3+
from httpx import Timeout
34
from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder
5+
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
46

57
from .lib.auth_client import SupabaseAuthClient
68
from .lib.client_options import ClientOptions
@@ -152,10 +154,16 @@ def _init_supabase_auth_client(
152154

153155
@staticmethod
154156
def _init_postgrest_client(
155-
rest_url: str, supabase_key: str, headers: Dict[str, str], schema: str
157+
rest_url: str,
158+
supabase_key: str,
159+
headers: Dict[str, str],
160+
schema: str,
161+
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
156162
) -> SyncPostgrestClient:
157163
"""Private helper for creating an instance of the Postgrest client."""
158-
client = SyncPostgrestClient(rest_url, headers=headers, schema=schema)
164+
client = SyncPostgrestClient(
165+
rest_url, headers=headers, schema=schema, timeout=timeout
166+
)
159167
client.auth(token=supabase_key)
160168
return client
161169

supabase/lib/client_options.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from dataclasses import dataclass, field
2-
from typing import Any, Callable, Dict, Optional
2+
from typing import Any, Callable, Dict, Optional, Union
33

44
from gotrue import SyncMemoryStorage, SyncSupportedStorage
5+
from httpx import Timeout
6+
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
57

68
from supabase import __version__
79

@@ -34,6 +36,9 @@ class ClientOptions:
3436
fetch: Optional[Callable] = None
3537
"""A custom `fetch` implementation."""
3638

39+
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
40+
"""Timeout passed to the SyncPostgrestClient instance."""
41+
3742
def replace(
3843
self,
3944
schema: Optional[str] = None,
@@ -43,6 +48,7 @@ def replace(
4348
local_storage: Optional[SyncSupportedStorage] = None,
4449
realtime: Optional[Dict[str, Any]] = None,
4550
fetch: Optional[Callable] = None,
51+
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
4652
) -> "ClientOptions":
4753
"""Create a new SupabaseClientOptions with changes"""
4854
client_options = ClientOptions()
@@ -55,4 +61,5 @@ def replace(
5561
client_options.local_storage = local_storage or self.local_storage
5662
client_options.realtime = realtime or self.realtime
5763
client_options.fetch = fetch or self.fetch
64+
client_options.timeout = timeout or self.timeout
5865
return client_options

0 commit comments

Comments
 (0)