From de5aba359ad21fd35f4e222f4693913b9777618e Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Fri, 15 Jul 2022 15:21:15 +0100 Subject: [PATCH 1/9] feat: setting timeout for postgrest-py client (#225) --- supabase/client.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/supabase/client.py b/supabase/client.py index 007b6d1e..336f0be9 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -1,11 +1,12 @@ -from typing import Any, Dict +from typing import Any, Dict, Union from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder +from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from .lib.auth_client import SupabaseAuthClient from .lib.client_options import ClientOptions from .lib.storage_client import SupabaseStorageClient - +from httpx import Timeout class Client: """Supabase client class.""" @@ -152,10 +153,14 @@ def _init_supabase_auth_client( @staticmethod def _init_postgrest_client( - rest_url: str, supabase_key: str, headers: Dict[str, str], schema: str + rest_url: str, + supabase_key: str, + headers: Dict[str, str], + schema: str, + timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT ) -> SyncPostgrestClient: """Private helper for creating an instance of the Postgrest client.""" - client = SyncPostgrestClient(rest_url, headers=headers, schema=schema) + client = SyncPostgrestClient(rest_url, headers=headers, schema=schema, timeout=timeout) client.auth(token=supabase_key) return client From 069ada2f14c44e96f20e60c31ad1fdb8d9beb9e4 Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Fri, 15 Jul 2022 15:32:20 +0100 Subject: [PATCH 2/9] feat: added timeout to options --- supabase/client.py | 2 ++ supabase/lib/client_options.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/supabase/client.py b/supabase/client.py index 336f0be9..5ed71613 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -48,6 +48,7 @@ def __init__( auth_url=self.auth_url, supabase_key=self.supabase_key, client_options=options, + ) # TODO(fedden): Bring up to parity with JS client. # self.realtime: SupabaseRealtimeClient = self._init_realtime_client( @@ -60,6 +61,7 @@ def __init__( supabase_key=self.supabase_key, headers=options.headers, schema=options.schema, + timeout=options.timeout ) def storage(self) -> SupabaseStorageClient: diff --git a/supabase/lib/client_options.py b/supabase/lib/client_options.py index f3cbffdd..23e87611 100644 --- a/supabase/lib/client_options.py +++ b/supabase/lib/client_options.py @@ -1,7 +1,9 @@ from dataclasses import dataclass, field -from typing import Any, Callable, Dict, Optional +from typing import Any, Callable, Dict, Optional, Union from gotrue import SyncMemoryStorage, SyncSupportedStorage +from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT +from httpx import Timeout from supabase import __version__ @@ -34,6 +36,9 @@ class ClientOptions: fetch: Optional[Callable] = None """A custom `fetch` implementation.""" + timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT + """Timeout passed to the SyncPostgrestClient instance.""" + def replace( self, schema: Optional[str] = None, @@ -43,6 +48,7 @@ def replace( local_storage: Optional[SyncSupportedStorage] = None, realtime: Optional[Dict[str, Any]] = None, fetch: Optional[Callable] = None, + timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT ) -> "ClientOptions": """Create a new SupabaseClientOptions with changes""" client_options = ClientOptions() @@ -55,4 +61,5 @@ def replace( client_options.local_storage = local_storage or self.local_storage client_options.realtime = realtime or self.realtime client_options.fetch = fetch or self.fetch + client_options.timeout = timeout or self.timeout return client_options From 3f518849385928f258d3ca5152c6ffb6da7d8e71 Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Fri, 15 Jul 2022 15:35:54 +0100 Subject: [PATCH 3/9] Revert "feat: added timeout to options" This reverts commit 069ada2f14c44e96f20e60c31ad1fdb8d9beb9e4. --- supabase/client.py | 2 -- supabase/lib/client_options.py | 9 +-------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/supabase/client.py b/supabase/client.py index 5ed71613..336f0be9 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -48,7 +48,6 @@ def __init__( auth_url=self.auth_url, supabase_key=self.supabase_key, client_options=options, - ) # TODO(fedden): Bring up to parity with JS client. # self.realtime: SupabaseRealtimeClient = self._init_realtime_client( @@ -61,7 +60,6 @@ def __init__( supabase_key=self.supabase_key, headers=options.headers, schema=options.schema, - timeout=options.timeout ) def storage(self) -> SupabaseStorageClient: diff --git a/supabase/lib/client_options.py b/supabase/lib/client_options.py index 23e87611..f3cbffdd 100644 --- a/supabase/lib/client_options.py +++ b/supabase/lib/client_options.py @@ -1,9 +1,7 @@ from dataclasses import dataclass, field -from typing import Any, Callable, Dict, Optional, Union +from typing import Any, Callable, Dict, Optional from gotrue import SyncMemoryStorage, SyncSupportedStorage -from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT -from httpx import Timeout from supabase import __version__ @@ -36,9 +34,6 @@ class ClientOptions: fetch: Optional[Callable] = None """A custom `fetch` implementation.""" - timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT - """Timeout passed to the SyncPostgrestClient instance.""" - def replace( self, schema: Optional[str] = None, @@ -48,7 +43,6 @@ def replace( local_storage: Optional[SyncSupportedStorage] = None, realtime: Optional[Dict[str, Any]] = None, fetch: Optional[Callable] = None, - timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT ) -> "ClientOptions": """Create a new SupabaseClientOptions with changes""" client_options = ClientOptions() @@ -61,5 +55,4 @@ def replace( client_options.local_storage = local_storage or self.local_storage client_options.realtime = realtime or self.realtime client_options.fetch = fetch or self.fetch - client_options.timeout = timeout or self.timeout return client_options From 136ce2576c859cf87175778e1569e073bb67aa63 Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Fri, 15 Jul 2022 15:38:01 +0100 Subject: [PATCH 4/9] feat: added timeout to options (#225) --- supabase/lib/client_options.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/supabase/lib/client_options.py b/supabase/lib/client_options.py index f3cbffdd..23e87611 100644 --- a/supabase/lib/client_options.py +++ b/supabase/lib/client_options.py @@ -1,7 +1,9 @@ from dataclasses import dataclass, field -from typing import Any, Callable, Dict, Optional +from typing import Any, Callable, Dict, Optional, Union from gotrue import SyncMemoryStorage, SyncSupportedStorage +from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT +from httpx import Timeout from supabase import __version__ @@ -34,6 +36,9 @@ class ClientOptions: fetch: Optional[Callable] = None """A custom `fetch` implementation.""" + timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT + """Timeout passed to the SyncPostgrestClient instance.""" + def replace( self, schema: Optional[str] = None, @@ -43,6 +48,7 @@ def replace( local_storage: Optional[SyncSupportedStorage] = None, realtime: Optional[Dict[str, Any]] = None, fetch: Optional[Callable] = None, + timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT ) -> "ClientOptions": """Create a new SupabaseClientOptions with changes""" client_options = ClientOptions() @@ -55,4 +61,5 @@ def replace( client_options.local_storage = local_storage or self.local_storage client_options.realtime = realtime or self.realtime client_options.fetch = fetch or self.fetch + client_options.timeout = timeout or self.timeout return client_options From a910474b6827f1e9dbf9f0dd5f127788ca6da29d Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Fri, 15 Jul 2022 20:00:33 +0100 Subject: [PATCH 5/9] feat: setting timeout for postgrest-py client. Closes #225 --- supabase/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase/client.py b/supabase/client.py index 336f0be9..7fd63407 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -2,11 +2,11 @@ from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT +from httpx import Timeout from .lib.auth_client import SupabaseAuthClient from .lib.client_options import ClientOptions from .lib.storage_client import SupabaseStorageClient -from httpx import Timeout class Client: """Supabase client class.""" From 4769dc4aa8fef866e1173cd3d1e39923ba0aadd6 Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Sat, 16 Jul 2022 06:52:44 +0100 Subject: [PATCH 6/9] feat: setting timeout for postgrest-py client. Closes #225 --- supabase/lib/client_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase/lib/client_options.py b/supabase/lib/client_options.py index 23e87611..b2c93b25 100644 --- a/supabase/lib/client_options.py +++ b/supabase/lib/client_options.py @@ -2,8 +2,8 @@ from typing import Any, Callable, Dict, Optional, Union from gotrue import SyncMemoryStorage, SyncSupportedStorage -from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from httpx import Timeout +from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from supabase import __version__ From 709ad8dd12f5654ba44c34b5a03e9d0c191a09e3 Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Sat, 16 Jul 2022 06:56:14 +0100 Subject: [PATCH 7/9] feat: setting timeout for postgrest-py client. Closes #225 --- supabase/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase/client.py b/supabase/client.py index 7fd63407..92e43977 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -1,8 +1,8 @@ from typing import Any, Dict, Union from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder -from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from httpx import Timeout +from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from .lib.auth_client import SupabaseAuthClient from .lib.client_options import ClientOptions From 258ddf12e2c5df8b30175c7a295934bc0f78133d Mon Sep 17 00:00:00 2001 From: kenneth gabriel Date: Sun, 17 Jul 2022 22:02:46 +0100 Subject: [PATCH 8/9] feat: setting timeout for postgrest-py client. Closes #225 --- supabase/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase/client.py b/supabase/client.py index 92e43977..918fed14 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Union -from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder from httpx import Timeout +from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from .lib.auth_client import SupabaseAuthClient From b1a73a0f18dedb075207d8f711db5918a0bce030 Mon Sep 17 00:00:00 2001 From: keosariel Date: Mon, 25 Jul 2022 19:54:24 +0100 Subject: [PATCH 9/9] fix: pass timeout to test --- tests/test_client_options.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_client_options.py b/tests/test_client_options.py index 46273ec0..4eb38eca 100644 --- a/tests/test_client_options.py +++ b/tests/test_client_options.py @@ -13,6 +13,7 @@ def test__client_options__replace__returns_updated_options(): persist_session=False, local_storage=local_storage, realtime={"key": "value"}, + timeout=5 ) actual = options.replace(schema="new schema") @@ -23,6 +24,7 @@ def test__client_options__replace__returns_updated_options(): persist_session=False, local_storage=local_storage, realtime={"key": "value"}, + timeout=5 ) assert actual == expected