Skip to content

Commit 28fe522

Browse files
authored
Merge pull request #381 from supabase-community/j0/add_storage_timeout
fix: add storage client timeout
2 parents cded695 + 57b340b commit 28fe522

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "supabase"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
description = "Supabase client for Python."
55
authors = ["Joel Lee <[email protected]>", "Leon Fedden <[email protected]>", "Daniel Reinón García <[email protected]>", "Leynier Gutiérrez González <[email protected]>", "Anand"]
66
homepage = "https://github.com/supabase-community/supabase-py"

Diff for: supabase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.1"
1+
__version__ = "1.0.2"

Diff for: supabase/client.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from httpx import Timeout
55
from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder
66
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
7+
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
78
from supafunc import FunctionsClient
89

910
from .lib.auth_client import SupabaseAuthClient
@@ -89,16 +90,15 @@ def __init__(
8990
supabase_key=self.supabase_key,
9091
headers=options.headers,
9192
schema=options.schema,
92-
timeout=options.timeout,
93+
timeout=options.postgrest_client_timeout,
94+
)
95+
self.storage = self._init_storage_client(
96+
self.storage_url, self._get_auth_headers(), options.storage_client_timeout
9397
)
9498

9599
def functions(self) -> FunctionsClient:
96100
return FunctionsClient(self.functions_url, self._get_auth_headers())
97101

98-
def storage(self) -> SupabaseStorageClient:
99-
"""Create instance of the storage client"""
100-
return SupabaseStorageClient(self.storage_url, self._get_auth_headers())
101-
102102
def table(self, table_name: str) -> SyncRequestBuilder:
103103
"""Perform a table operation.
104104
@@ -168,6 +168,13 @@ def rpc(self, fn: str, params: Dict[Any, Any]) -> SyncFilterRequestBuilder:
168168
# return SupabaseRealtimeClient(
169169
# realtime_url, {"params": {"apikey": supabase_key}}
170170
# )
171+
@staticmethod
172+
def _init_storage_client(
173+
storage_url: str,
174+
headers: Dict[str, str],
175+
storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT,
176+
) -> SupabaseStorageClient:
177+
return SupabaseStorageClient(storage_url, headers, storage_client_timeout)
171178

172179
@staticmethod
173180
def _init_supabase_auth_client(

Diff for: supabase/lib/client_options.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from gotrue import SyncMemoryStorage, SyncSupportedStorage
55
from httpx import Timeout
66
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
7+
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
78

89
from supabase import __version__
910

@@ -36,9 +37,14 @@ class ClientOptions:
3637
fetch: Optional[Callable] = None
3738
"""A custom `fetch` implementation."""
3839

39-
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
40+
postgrest_client_timeout: Union[
41+
int, float, Timeout
42+
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
4043
"""Timeout passed to the SyncPostgrestClient instance."""
4144

45+
storage_client_timeout: Union[int, float, Timeout] = DEFAULT_STORAGE_CLIENT_TIMEOUT
46+
"""Timeout passed to the SyncStorageClient instance"""
47+
4248
def replace(
4349
self,
4450
schema: Optional[str] = None,
@@ -48,7 +54,12 @@ def replace(
4854
storage: Optional[SyncSupportedStorage] = None,
4955
realtime: Optional[Dict[str, Any]] = None,
5056
fetch: Optional[Callable] = None,
51-
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
57+
postgrest_client_timeout: Union[
58+
int, float, Timeout
59+
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
60+
storage_client_timeout: Union[
61+
int, float, Timeout
62+
] = DEFAULT_STORAGE_CLIENT_TIMEOUT,
5263
) -> "ClientOptions":
5364
"""Create a new SupabaseClientOptions with changes"""
5465
client_options = ClientOptions()
@@ -61,5 +72,10 @@ def replace(
6172
client_options.storage = storage or self.storage
6273
client_options.realtime = realtime or self.realtime
6374
client_options.fetch = fetch or self.fetch
64-
client_options.timeout = timeout or self.timeout
75+
client_options.postgrest_client_timeout = (
76+
postgrest_client_timeout or self.postgrest_client_timeout
77+
)
78+
client_options.storage_client_timeout = (
79+
storage_client_timeout or self.storage_client_timeout
80+
)
6581
return client_options

0 commit comments

Comments
 (0)