Skip to content

Improve client validation and ClientOptions.replace correctness - #1398

Closed
AhmedAli58 wants to merge 2 commits into
supabase:mainfrom
AhmedAli58:codex/fix-storage-url-trailing-slash
Closed

AhmedAli58 wants to merge 2 commits into
supabase:mainfrom
AhmedAli58:codex/fix-storage-url-trailing-slash

Conversation

@AhmedAli58

@AhmedAli58 AhmedAli58 commented Feb 18, 2026 •

Copy link
Copy Markdown

Summary

This PR introduces three targeted quality improvements in the supabase package:

  1. Strengthened client constructor input validation.
  2. Corrected falsy override handling in ClientOptions.replace().
  3. Fixed configuration integrity gaps in ClientOptions.replace().

All changes are covered by tests. Linting and the full test suite pass.


1. Strengthened Client Input Validation

Problem

Constructor validation for supabase_url and supabase_key was inconsistent. Non-string or invalid values could raise raw TypeError or bypass validation, resulting in low-quality or unclear errors.

Changes

  • Added explicit runtime validation for:
    • Non-empty string URL and key
    • Valid URL scheme checks
  • Standardized failures to raise SupabaseException
  • Updated tests to use strict pytest.raises instead of weak xfail patterns

Impact

Invalid constructor inputs now fail deterministically and consistently with clear exceptions.


2. Fixed Falsy Override Handling in ClientOptions.replace()

Problem

or-based assignment caused explicit falsy values (False, 0, {}) to be ignored, silently preserving previous configuration values.

Changes

  • Replaced or logic with explicit is None checks
  • Added regression tests covering falsy override scenarios

Impact

Callers can now reliably override configuration with valid falsy values.


3. Fixed Configuration Integrity Gaps in ClientOptions.replace()

Problems

  • function_client_timeout was not preserved or correctly overridden.
  • Header dictionaries were reused, creating shared mutable state between instances.

Changes

  • Added proper handling of function_client_timeout in both async and sync implementations.
  • Copied header dictionaries when constructing replacement options.
  • Added tests verifying:
    • Timeout preservation and override behavior
    • Header isolation (no shared mutation)

Impact

Replaced option objects are now configuration-safe and free from unintended mutation coupling.


Testing

  • make ruff -> passed
  • make supabase.tests -> 55 tests passed
  • Added new regression tests for:
    • Constructor validation behavior
    • Falsy overrides
    • Timeout preservation
    • Header isolation

Scope

  • Changes are limited to:
    • Client validation logic
    • ClientOptions.replace() implementations (async and sync)
    • Associated test updates
  • No unrelated files were modified.

Validation Checklist

  • Lint passes
  • Test suite passes
  • Behavior preserved unless correcting a defect
  • Tests added for new logic
  • Changes are scoped and reviewable

@coderabbitai

coderabbitai Bot commented Feb 18, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2d2c05a and 9f7eb97.

📒 Files selected for processing (6)
  • src/supabase/src/supabase/_async/client.py
  • src/supabase/src/supabase/_sync/client.py
  • src/supabase/src/supabase/lib/client_options.py
  • src/supabase/tests/_async/test_client.py
  • src/supabase/tests/_sync/test_client.py
  • src/supabase/tests/test_client_options.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/supabase/tests/_sync/test_client.py

📝 Walkthrough

Summary by CodeRabbit

  • Tests

    • Added regression tests ensuring storage base URL includes the required trailing slash for both sync and async clients.
    • Expanded client-options tests to verify replacement behavior, header copying, and timeout handling.
  • Bug Fixes / Behavior

    • Client input validation now consistently rejects invalid URL/key combinations with clearer errors.
    • Client configuration merging is more predictable: passing None preserves existing settings and falsy values (e.g., False, 0, {}) are accepted as intended.

Walkthrough

This PR centralizes input validation by adding _validate_client_inputs(...) and calling it from both AsyncClient.init and Client.init. It refactors ClientOptions.replace (async and sync) to use explicit None-based merging, adds function_client_timeout and makes several timeout parameters Optional. Tests were updated: incorrect-values client tests were parameterized and now use pytest.raises for exceptions; a regression test test_storage_base_url_has_trailing_slash was added to both sync and async test modules (duplicated in the sync file); new tests cover ClientOptions.replace behaviors (falsy values, header copying, function_client_timeout).

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

@AhmedAli58 AhmedAli58 changed the title test(supabase): add storage trailing slash regression coverage Improve client validation and ClientOptions.replace correctness Feb 25, 2026
@o-santi

o-santi commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

I don't think this is needed, as the code is fully type checked. If the user passes in a non-string as the url, mypy should be able to warn him of the mistake and the user should correct him. If he ignores mypy, then the code would already break, and we don't want to incentivize users to ignore type checkers, for they offer great information on the API is to be used.

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.

2 participants