Skip to content

Use None check for request.id to preserve falsy IDs - #3143

Open
bysiber wants to merge 1 commit into
sanic-org:mainfrom
bysiber:fix-request-id-none-check
Open

Use None check for request.id to preserve falsy IDs#3143
bysiber wants to merge 1 commit into
sanic-org:mainfrom
bysiber:fix-request-id-none-check

Conversation

@bysiber

@bysiber bysiber commented Feb 20, 2026

Copy link
Copy Markdown

The request.id property uses if not self._id to decide whether to generate/fetch the ID. This treats any falsy value (including 0, "") as "not yet set," causing the ID to be regenerated on every property access.

A custom generate_id() returning 0 or an integer request ID header value of "0" (which gets cast to int(0)) would trigger re-generation every time request.id is read. Switching to is None preserves any explicitly-set falsy ID while still triggering lazy initialization when genuinely unset.

@bysiber
bysiber requested a review from a team as a code owner February 20, 2026 03:48
@codecov

codecov Bot commented Feb 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.817%. Comparing base (785d77f) to head (b712c5c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #3143       +/-   ##
=============================================
+ 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 Harness.
📢 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.

@themavik themavik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using is None for request._id fixes legitimate falsy ids (0, ""). nit: a bytes-like falsy id would still be regenerated—only matters if headers can surface that type.

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