Skip to content

fix(storage)!: take upsert as a bool in upload and create_signed_upload_url - #1997

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/1996-storage-upsert-bool
Nov 5, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/1996-storage-upsert-bool

Conversation

@spydon

@spydon spydon commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What

The storage upload methods took upsert as a string and copied it straight into the x-upsert header. This PR types it as a bool, in line with storage-js (upsert?: boolean).

  • upload(): upsert: bool = False, sent as x-upsert: true or x-upsert: false.
  • create_signed_upload_url(): upsert: bool | None = None. The header is only sent when the argument is set, so the server default still applies when it is omitted. Passing upsert=False now sends x-upsert: false instead of being dropped.
  • update(): the upsert argument is removed. update() uses PUT, which never sent the header, so the argument did nothing.
  • A non-bool upsert raises TypeError. Without this check, a leftover upsert="false" would be truthy and be sent as x-upsert: true, overwriting files silently.
  • MIGRATION.md gets a section on the storage upsert change.

Why

  • upsert=True failed inside httpx with TypeError: Header value must be str or bytes, not <class 'bool'>.
  • Any string passed the type check, so values like "True" or "yes" were sent unchanged and could silently fail to overwrite.

Breaking change

  • Callers passing upsert="true" or upsert="false" must pass True or False.
  • Callers passing upsert= to update() must remove it.

This targets main (v3) only.

Tests

Added unit tests for the x-upsert header value of upload() and create_signed_upload_url(), and for the TypeError on a string upsert, for both the sync and async clients.

Closes #1996

…ad_url

BREAKING CHANGE: upload() and create_signed_upload_url() now take upsert as a bool instead of a string. update() no longer accepts upsert, since it was never sent.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Upload and signed-upload options now accept boolean upsert values. Signed uploads leave the option unspecified when omitted, allowing the server default to apply.
  • Bug Fixes
    • Uploads now send the selected upsert setting consistently. The update operation no longer accepts an upsert option, which previously had no effect.
  • Documentation
    • Updated the migration guide with the revised upsert behavior and examples.

The storage upload API now accepts boolean upsert values and serializes them as lowercase strings in the x-upsert header. Signed-upload URL creation omits the header when upsert is None. upload defaults to False. update no longer accepts upsert and omits the header.

Assessment against linked issues

Objective Addressed Explanation
Use boolean upsert values and send "true" or "false" for uploads and signed-upload URL creation [#1996] ✅
Omit the signed-upload header when upsert is unset, and remove the ineffective update parameter [#1996] ✅
Add tests for header values and both clients [#1996] ✅

Possibly related PRs

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 81bba

No merge-blocking issue is identified. The boolean upsert API and removal of update's upsert argument are documented breaking changes intended for v3.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b24b64b-6cbc-4b44-aac3-1364d4f3c7e9
Commits

Reviewing files that changed from the base of the PR and between b54cba4 and 81bba37.

Files selected for processing: 3

  • MIGRATION.md
  • src/storage/src/storage3/file_api.py
  • src/storage/tests/test_file_api.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

@spydon
spydon merged commit 0331c57 into main Nov 5, 2026
29 checks passed
@spydon
spydon deleted the lukasklingsbo/1996-storage-upsert-bool branch November 5, 2026 12:24
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: upsert is a string that is sent unchecked as the x-upsert header

1 participant