Skip to content

fix(storage3): replace print() with warnings.warn() for trailing slash notice - #1380

Merged
o-santi merged 1 commit into
supabase:mainfrom
bishnubista:fix/storage3-print-to-warnings
Feb 9, 2026
Merged

o-santi merged 1 commit into
supabase:mainfrom
bishnubista:fix/storage3-print-to-warnings

Conversation

@bishnubista

@bishnubista bishnubista commented Feb 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1379

Problem

The storage3 module uses bare print() to emit a notice when the storage endpoint URL lacks a trailing slash:

# _sync/bucket.py and _async/bucket.py
if url and url[-1] != "/":
    print("Storage endpoint URL should have a trailing slash.")
    url += "/"

While PR #1367 (v2.27.3) fixed the SDK side by ensuring the URL always ends with /, the print() call remains problematic for direct consumers of storage3:

  • Pollutes stdout — interferes with piped commands, structured logging, and test output capture
  • Cannot be suppressed — unlike warnings.warn(), consumers have no way to filter or silence it
  • No stack trace context — developers can't trace where the URL was constructed
  • Library auto-corrects — the URL is fixed immediately after the print, making the message noise

Solution

Replace print() with warnings.warn() using:

  • UserWarning category (standard for usage notices)
  • stacklevel=2 so the warning points to the caller, not the internal __init__
warnings.warn(
    "Storage endpoint URL should have a trailing slash. "
    "The URL has been automatically corrected.",
    UserWarning,
    stacklevel=2,
)

This follows Python best practices and gives consumers control via warnings.filterwarnings().

Changes

  • src/storage/src/storage3/_sync/bucket.py — import warnings, replace print() with warnings.warn()
  • src/storage/src/storage3/_async/bucket.py — same change (async variant)

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Storage endpoint URLs without trailing slashes now issue formal warning notifications. URLs are automatically corrected to include the trailing slash, improving visibility of this automatic correction.

…h notice

The storage3 module used print() to notify about missing trailing slashes
in the endpoint URL. This is problematic because print() pollutes stdout,
cannot be suppressed by consumers, and provides no stack trace context.

Replace with warnings.warn() using UserWarning category and stacklevel=2
so the warning points to the caller rather than the internal __init__.
This follows Python best practices and gives consumers control via
warnings.filterwarnings().

Fixes supabase#1379

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Feb 6, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Replaces print() calls with warnings.warn() in the storage3 module's bucket initialization code for both sync and async variants, enabling users to control whether trailing slash correction notifications are displayed.

Changes

Cohort / File(s) Summary
Sync and Async Bucket Initialization
src/storage/src/storage3/_sync/bucket.py, src/storage/src/storage3/_async/bucket.py
Added warnings import and replaced print() with warnings.warn(..., UserWarning, stacklevel=2) when storage endpoint URL lacks trailing slash, allowing suppression/filtering of the notification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • o-santi
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: replacing print() with warnings.warn() for the trailing slash notice, which matches the core objective of the PR.
Linked Issues check ✅ Passed The PR successfully implements all requirements from #1379: replaces print() with warnings.warn() in both _sync and _async modules, uses UserWarning category, implements stacklevel=2, and includes the auto-correct message.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements: only the two bucket.py files are modified with the necessary import and warning replacement, no unrelated alterations present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 21763714864

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 91.161%

Totals Coverage Status
Change from base Build 21760527869: 0.002%
Covered Lines: 9004
Relevant Lines: 9877

💛 - Coveralls

@o-santi
o-santi merged commit 50b099f into supabase:main Feb 9, 2026
41 checks passed
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.

storage3: Replace print() with warnings.warn() for trailing slash notice

3 participants