Fix/issue 1244 shared httpx client url mutation #1246
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Resolve shared httpx client base_url mutation across services
Overview
This PR resolves GitHub Issue #1244 - a critical bug where shared
httpx.Client
instances cause URL corruption between Supabase services (Storage, PostgREST, Functions). The issue occurred when multiple services mutated the same client'sbase_url
property, causing API requests to hit wrong endpoints.** Problem**: Storage calls would fail after accessing PostgREST, hitting
/rest/v1/
instead of/storage/v1/
** Solution**: Implemented client isolation pattern with configuration preservation
** Result**: All services maintain correct URLs while preserving shared httpx configuration
🔍 Problem Analysis
Root Cause Identified
The bug occurred because multiple Supabase services shared the same
httpx.Client
instance and directly mutated itsbase_url
property:Impact:
/storage/v1/
to/rest/v1/
Reproduction Confirmed
Created comprehensive test cases showing:
Technical Solution
Core Strategy: Client Isolation with Configuration Preservation
Instead of mutating shared clients, I implemented a pattern that creates isolated
httpx.Client
instances while preserving all shared configuration:Key Benefits
Files Modified
Service Client Implementations (8 files)
src/storage/src/storage3/_sync/client.py
- Storage sync client isolationsrc/storage/src/storage3/_async/client.py
- Storage async client isolationsrc/postgrest/src/postgrest/_sync/client.py
- PostgREST sync client isolationsrc/postgrest/src/postgrest/_async/client.py
- PostgREST async client isolationsrc/functions/src/supabase_functions/_sync/functions_client.py
- Functions sync client isolationsrc/functions/src/supabase_functions/_async/functions_client.py
- Functions async client isolationsrc/supabase/src/supabase/_sync/client.py
- Main Supabase sync client coordinationsrc/supabase/src/supabase/_async/client.py
- Main Supabase async client coordinationDocumentation Updates
CHANGELOG.md
- Comprehensive changelog entry with technical detailsDependencies
uv.lock
- Updated dependency lock fileMessage to Maintainers:
@silentworks
@olirice
This is one of my first contributions to open source, and I’m excited to be part of the community. I’m open to any guidance, feedback, or improvements that can help me learn and make this contribution more valuable.