diff --git a/src/supabase/src/supabase/lib/client_options.py b/src/supabase/src/supabase/lib/client_options.py index 8a92f73a5..c3a21b604 100644 --- a/src/supabase/src/supabase/lib/client_options.py +++ b/src/supabase/src/supabase/lib/client_options.py @@ -83,10 +83,8 @@ def replace( storage: Optional[AsyncSupportedStorage] = None, realtime: Optional[RealtimeClientOptions] = None, httpx_client: Optional[AsyncHttpxClient] = None, - postgrest_client_timeout: Union[ - int, float, Timeout - ] = DEFAULT_POSTGREST_CLIENT_TIMEOUT, - storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT, + postgrest_client_timeout: Optional[Union[int, float, Timeout]] = None, + storage_client_timeout: Optional[int] = None, flow_type: Optional[AuthFlowType] = None, function_client_timeout: Optional[int] = None, ) -> "AsyncClientOptions": @@ -106,10 +104,14 @@ def replace( client_options.realtime = realtime or self.realtime client_options.httpx_client = httpx_client or self.httpx_client client_options.postgrest_client_timeout = ( - postgrest_client_timeout or self.postgrest_client_timeout + postgrest_client_timeout + if postgrest_client_timeout is not None + else self.postgrest_client_timeout ) client_options.storage_client_timeout = ( - storage_client_timeout or self.storage_client_timeout + storage_client_timeout + if storage_client_timeout is not None + else self.storage_client_timeout ) client_options.flow_type = flow_type or self.flow_type client_options.function_client_timeout = ( @@ -136,10 +138,8 @@ def replace( storage: Optional[SyncSupportedStorage] = None, realtime: Optional[RealtimeClientOptions] = None, httpx_client: Optional[SyncHttpxClient] = None, - postgrest_client_timeout: Union[ - int, float, Timeout - ] = DEFAULT_POSTGREST_CLIENT_TIMEOUT, - storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT, + postgrest_client_timeout: Optional[Union[int, float, Timeout]] = None, + storage_client_timeout: Optional[int] = None, flow_type: Optional[AuthFlowType] = None, function_client_timeout: Optional[int] = None, ) -> "SyncClientOptions": @@ -159,10 +159,14 @@ def replace( client_options.realtime = realtime or self.realtime client_options.httpx_client = httpx_client or self.httpx_client client_options.postgrest_client_timeout = ( - postgrest_client_timeout or self.postgrest_client_timeout + postgrest_client_timeout + if postgrest_client_timeout is not None + else self.postgrest_client_timeout ) client_options.storage_client_timeout = ( - storage_client_timeout or self.storage_client_timeout + storage_client_timeout + if storage_client_timeout is not None + else self.storage_client_timeout ) client_options.flow_type = flow_type or self.flow_type client_options.function_client_timeout = ( diff --git a/src/supabase/tests/_async/test_client.py b/src/supabase/tests/_async/test_client.py index 24457095d..14914767a 100644 --- a/src/supabase/tests/_async/test_client.py +++ b/src/supabase/tests/_async/test_client.py @@ -238,6 +238,19 @@ async def test_replace_preserves_and_overrides_function_timeout() -> None: assert client.functions._client.timeout == Timeout(30) +async def test_replace_preserves_and_overrides_postgrest_and_storage_timeouts() -> None: + options = AsyncClientOptions(postgrest_client_timeout=5, storage_client_timeout=7) + + updated = options.replace(schema="private") + assert updated.postgrest_client_timeout == 5 + assert updated.storage_client_timeout == 7 + assert updated.schema == "private" + + overridden = updated.replace(postgrest_client_timeout=9, storage_client_timeout=11) + assert overridden.postgrest_client_timeout == 9 + assert overridden.storage_client_timeout == 11 + + async def test_custom_headers_immutable() -> None: url = os.environ["SUPABASE_TEST_URL"] key = os.environ["SUPABASE_TEST_KEY"] diff --git a/src/supabase/tests/_sync/test_client.py b/src/supabase/tests/_sync/test_client.py index 6af4c55e6..7e011130f 100644 --- a/src/supabase/tests/_sync/test_client.py +++ b/src/supabase/tests/_sync/test_client.py @@ -236,6 +236,19 @@ def test_replace_preserves_and_overrides_function_timeout() -> None: assert client.functions._client.timeout == Timeout(30) +def test_replace_preserves_and_overrides_postgrest_and_storage_timeouts() -> None: + options = ClientOptions(postgrest_client_timeout=5, storage_client_timeout=7) + + updated = options.replace(schema="private") + assert updated.postgrest_client_timeout == 5 + assert updated.storage_client_timeout == 7 + assert updated.schema == "private" + + overridden = updated.replace(postgrest_client_timeout=9, storage_client_timeout=11) + assert overridden.postgrest_client_timeout == 9 + assert overridden.storage_client_timeout == 11 + + def test_custom_headers_immutable() -> None: url = os.environ["SUPABASE_TEST_URL"] key = os.environ["SUPABASE_TEST_KEY"]