Skip to content

Commit

Permalink
Merge pull request supabase#381 from supabase-community/j0/add_storag…
Browse files Browse the repository at this point in the history
…e_timeout

fix: add storage client timeout
  • Loading branch information
J0 authored Mar 9, 2023
2 parents cded695 + 57b340b commit 28fe522
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "supabase"
version = "1.0.1"
version = "1.0.2"
description = "Supabase client for Python."
authors = ["Joel Lee <[email protected]>", "Leon Fedden <[email protected]>", "Daniel Reinón García <[email protected]>", "Leynier Gutiérrez González <[email protected]>", "Anand"]
homepage = "https://github.com/supabase-community/supabase-py"
Expand Down
2 changes: 1 addition & 1 deletion supabase/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.0.2"
17 changes: 12 additions & 5 deletions supabase/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from httpx import Timeout
from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
from supafunc import FunctionsClient

from .lib.auth_client import SupabaseAuthClient
Expand Down Expand Up @@ -89,16 +90,15 @@ def __init__(
supabase_key=self.supabase_key,
headers=options.headers,
schema=options.schema,
timeout=options.timeout,
timeout=options.postgrest_client_timeout,
)
self.storage = self._init_storage_client(
self.storage_url, self._get_auth_headers(), options.storage_client_timeout
)

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

def storage(self) -> SupabaseStorageClient:
"""Create instance of the storage client"""
return SupabaseStorageClient(self.storage_url, self._get_auth_headers())

def table(self, table_name: str) -> SyncRequestBuilder:
"""Perform a table operation.
Expand Down Expand Up @@ -168,6 +168,13 @@ def rpc(self, fn: str, params: Dict[Any, Any]) -> SyncFilterRequestBuilder:
# return SupabaseRealtimeClient(
# realtime_url, {"params": {"apikey": supabase_key}}
# )
@staticmethod
def _init_storage_client(
storage_url: str,
headers: Dict[str, str],
storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT,
) -> SupabaseStorageClient:
return SupabaseStorageClient(storage_url, headers, storage_client_timeout)

@staticmethod
def _init_supabase_auth_client(
Expand Down
22 changes: 19 additions & 3 deletions supabase/lib/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from gotrue import SyncMemoryStorage, SyncSupportedStorage
from httpx import Timeout
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT

from supabase import __version__

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

timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
"""Timeout passed to the SyncPostgrestClient instance."""

storage_client_timeout: Union[int, float, Timeout] = DEFAULT_STORAGE_CLIENT_TIMEOUT
"""Timeout passed to the SyncStorageClient instance"""

def replace(
self,
schema: Optional[str] = None,
Expand All @@ -48,7 +54,12 @@ def replace(
storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[Dict[str, Any]] = None,
fetch: Optional[Callable] = None,
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
storage_client_timeout: Union[
int, float, Timeout
] = DEFAULT_STORAGE_CLIENT_TIMEOUT,
) -> "ClientOptions":
"""Create a new SupabaseClientOptions with changes"""
client_options = ClientOptions()
Expand All @@ -61,5 +72,10 @@ def replace(
client_options.storage = storage or self.storage
client_options.realtime = realtime or self.realtime
client_options.fetch = fetch or self.fetch
client_options.timeout = timeout or self.timeout
client_options.postgrest_client_timeout = (
postgrest_client_timeout or self.postgrest_client_timeout
)
client_options.storage_client_timeout = (
storage_client_timeout or self.storage_client_timeout
)
return client_options

0 comments on commit 28fe522

Please sign in to comment.