Skip to content

fix(postgrest): apply normalized timeout to internal httpx clients - #1758

Open
AleksaMCode wants to merge 1 commit into
supabase:mainfrom
AleksaMCode:fix/postgrest-default-timeout
Open

AleksaMCode wants to merge 1 commit into
supabase:mainfrom
AleksaMCode:fix/postgrest-default-timeout

Conversation

@AleksaMCode

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix (PostgREST client timeout handling) + regression tests. Before applying the fix my tests would fail with:

src\postgrest\tests\_sync\test_client.py F                                                                                                                                                                                                                                    [ 50%]
src\postgrest\tests\_async\test_client.py F                                                                                                                                                                                                                                   [100%]

===================================================================================================================================== FAILURES ===================================================================================================================================== 
___________________________________________________________________________________________________________ TestConstructor.test_default_timeout_uses_postgrest_constant ___________________________________________________________________________________________________________ 

self = <tests._sync.test_client.TestConstructor object at 0x000001C29B21B390>

    def test_default_timeout_uses_postgrest_constant(self) -> None:
        with SyncPostgrestClient("https://example.com") as client:
            assert client.timeout == DEFAULT_POSTGREST_CLIENT_TIMEOUT
>           assert client.session.timeout == Timeout(
                timeout=DEFAULT_POSTGREST_CLIENT_TIMEOUT
            )
E           assert Timeout(timeout=None) == Timeout(timeout=120)
E            +  where Timeout(timeout=None) = <httpx.Client object at 0x000001C29B23ECF0>.timeout
E            +    where <httpx.Client object at 0x000001C29B23ECF0> = <postgrest._sync.client.SyncPostgrestClient object at 0x000001C29B23DE80>.session
E            +  and   Timeout(timeout=120) = Timeout(timeout=120)

src\postgrest\tests\_sync\test_client.py:56: AssertionError
___________________________________________________________________________________________________________ TestConstructor.test_default_timeout_uses_postgrest_constant ___________________________________________________________________________________________________________ 

self = <tests._async.test_client.TestConstructor object at 0x000001C29B21BB10>

    @pytest.mark.asyncio
    async def test_default_timeout_uses_postgrest_constant(self) -> None:
        async with AsyncPostgrestClient("https://example.com") as client:
            assert client.timeout == DEFAULT_POSTGREST_CLIENT_TIMEOUT
>           assert client.session.timeout == Timeout(
                timeout=DEFAULT_POSTGREST_CLIENT_TIMEOUT
            )
E           assert Timeout(timeout=None) == Timeout(timeout=120)
E            +  where Timeout(timeout=None) = <httpx.AsyncClient object at 0x000001C29B526510>.timeout
E            +    where <httpx.AsyncClient object at 0x000001C29B526510> = <postgrest._async.client.AsyncPostgrestClient object at 0x000001C29B5263C0>.session
E            +  and   Timeout(timeout=120) = Timeout(timeout=120)

src\postgrest\tests\_async\test_client.py:57: AssertionError
============================================================================================================================= short test summary info ============================================================================================================================== 
FAILED src\postgrest\tests\_sync\test_client.py::TestConstructor::test_default_timeout_uses_postgrest_constant - assert Timeout(timeout=None) == Timeout(timeout=120)
FAILED src\postgrest\tests\_async\test_client.py::TestConstructor::test_default_timeout_uses_postgrest_constant - assert Timeout(timeout=None) == Timeout(timeout=120)
========================================================================================================================= 2 failed

What is the current behavior?

When constructing SyncPostgrestClient / AsyncPostgrestClient without a custom http_client, the client computes a normalized timeout (self.timeout) and defaults it to DEFAULT_POSTGREST_CLIENT_TIMEOUT (120), but the internal HTTPX client is created with the raw timeout argument instead.

As a result, omitting timeout falls back to HTTPX defaults (about 5s per phase) instead of the intended PostgREST default.

I discovered this during usage when request timeout behavior was shorter than expected.

Relevant paths:

  • src/postgrest/src/postgrest/_sync/client.py
  • src/postgrest/src/postgrest/_async/client.py

What is the new behavior?

The internal HTTPX clients now use the normalized timeout (self.timeout) so runtime behavior matches the PostgREST client default and constructor logic.

This PR also adds regression tests (sync + async) that verify default timeout behavior when no custom http_client is supplied:

  • src/postgrest/tests/_sync/test_client.py
  • src/postgrest/tests/_async/test_client.py

Additional context

This change keeps behavior for custom http_client unchanged (caller-managed timeout still applies there).

I added tests first to capture the bug, confirmed they fail against current behavior, then applied the minimal fix.

@AleksaMCode
AleksaMCode requested a review from o-santi as a code owner October 18, 2026 13:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant