Skip to content

Assign datetime.replace() return value in validate_file#3141

Open
bysiber wants to merge 1 commit into
sanic-org:mainfrom
bysiber:fix-datetime-replace-return
Open

Assign datetime.replace() return value in validate_file#3141
bysiber wants to merge 1 commit into
sanic-org:mainfrom
bysiber:fix-datetime-replace-return

Conversation

@bysiber
Copy link
Copy Markdown

@bysiber bysiber commented Feb 20, 2026

validate_file() calls datetime.replace(tzinfo=timezone.utc) to normalize tz-naive datetimes before comparing last_modified and if_modified_since timestamps. However, datetime.replace() returns a new datetime — it doesn't mutate in place. Since the return values aren't assigned back, both variables remain tz-naive after the "fix."

The practical effect: on any server not running in UTC, last_modified.timestamp() interprets the tz-naive datetime as local time while the tz-aware one is interpreted as UTC. This produces incorrect comparisons and breaks HTTP 304 Not Modified responses — either serving stale content or forcing unnecessary re-downloads depending on the timezone offset direction.

@bysiber bysiber requested a review from a team as a code owner February 20, 2026 03:47
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.817%. Comparing base (785d77f) to head (371533d).

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #3141       +/-   ##
=============================================
+ Coverage   87.793%   87.817%   +0.024%     
=============================================
  Files          105       105               
  Lines         8143      8143               
  Branches      1290      1290               
=============================================
+ Hits          7149      7151        +2     
+ Misses         687       686        -1     
+ Partials       307       306        -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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