Skip to content

Format the expires header locale-independently - #705

Merged
ffumero2003 merged 2 commits into
masterfrom
fix-py-http-date-locale
Nov 21, 2026
Merged

ffumero2003 merged 2 commits into
masterfrom
fix-py-http-date-locale

Conversation

@ffumero2003

Copy link
Copy Markdown
Contributor

Context

Bucket formatted the "expires" header with locale-dependent strftime('%a, %d %b %Y %H:%M:%S GMT'), so on a host with a non-English LC_TIME the day/month names were wrong (e.g. Do, 01 Dez ...).

Changes

Use a locale-independent formatter (email.utils.format_datetime(expires, usegmt=True)).

Verification

Regression asserts the header stays English regardless of locale, and runs on any host (no dependency on an installed OS locale): it passes with the fix and fails if reverted (Do, 01 Dez vs Thu, 01 Dec). Bucket unit suite green; ruff clean; SDK panel PASS.

Refs #703

The C32 expires-header regression previously skipped on hosts with no
non-English locale installed, so CI could not catch a recurrence of the
locale-dependent strftime formatting. Replace the setlocale dance with a
monkeypatch that forces the bucket module's datetime.strftime to emit
non-English day/month names, so the test runs everywhere and fails if the
formatter reverts to locale-dependent output.
@ffumero2003 ffumero2003 self-assigned this Nov 21, 2026
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The bucket now formats datetime expiration values with format_datetime after converting them to UTC. The C32 regression test simulates foreign day and month names and checks the uploaded b2-expires value without changing the host locale. A changelog entry documents the fix.

Severity of issue fixed: Low

Merge Risk: Minimal · up to b8ac3

This change makes the expires header use English day and month names regardless of host locale. It is a small, localized fix with a regression test, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the expires header is now formatted without depending on the host locale. It matches the summary, which switches the Bucket expires formatting from locale-dependent st…
Description check Passed The description explains the problem, which is locale-dependent strftime formatting of the expires header that produced wrong day and month names. It names the fix, which uses email.utils.format_datet…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the expires header is now formatted without depending on the host locale. It matches the summary, which switches the Bucket expires formatting from locale-dependent strftime to email.utils.format_datetime with usegmt=True.

Full details: Description check

Explanation

The description explains the problem, which is locale-dependent strftime formatting of the expires header that produced wrong day and month names. It names the fix, which uses email.utils.format_datetime(expires, usegmt=True). It also describes the regression test and the verification steps. All of this matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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: 0a858cdc-d80c-4466-96a8-c32413d46b53
Commits

Reviewing files that changed from the base of the PR and between 03b99b3 and b8ac328.

Files selected for processing: 3

  • b2sdk/_internal/bucket.py
  • changelog.d/+http-date-locale.fixed.md
  • test/unit/bucket/test_regression_bucket.py

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

@ffumero2003
ffumero2003 merged commit 08f06b3 into master Nov 21, 2026
29 checks passed
@ffumero2003
ffumero2003 deleted the fix-py-http-date-locale branch November 21, 2026 20:36
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