Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/supabase/src/supabase/lib/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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 = (
Expand All @@ -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":
Expand All @@ -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 = (
Expand Down
13 changes: 13 additions & 0 deletions src/supabase/tests/_async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions src/supabase/tests/_sync/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading