Skip to content

fix: preserve count=0 in RunClient.charge#751

Open
vdusek wants to merge 1 commit intomasterfrom
fix/run-charge-preserve-zero-count
Open

fix: preserve count=0 in RunClient.charge#751
vdusek wants to merge 1 commit intomasterfrom
fix/run-charge-preserve-zero-count

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented Apr 22, 2026

Summary

RunClient.charge (and its async counterpart) built the request body with 'count': count or 1. The short-circuit or treats 0 as falsy, so a caller passing count=0 — e.g. count=len(batch) where the batch ended up empty, or a defensive no-op — was silently billed as count=1. On a pay-per-event billing endpoint the difference is financially material.

Replaced count or 1 with an explicit count if count is not None else 1 at both call sites, and clarified the docstring so the count=0 behaviour is documented rather than implicit.

Added a parametrized unit test (tests/unit/test_run_charge.py) covering None, 0, 1, and 5 for both sync and async clients; the 0 case fails on master and passes with this fix.

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Apr 22, 2026
@vdusek vdusek self-assigned this Apr 22, 2026
@github-actions github-actions Bot added this to the 139th sprint - Tooling team milestone Apr 22, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Apr 22, 2026
@vdusek vdusek requested a review from Pijukatel April 22, 2026 07:49
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.22%. Comparing base (9ab096a) to head (0faf061).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #751   +/-   ##
=======================================
  Coverage   95.22%   95.22%           
=======================================
  Files          45       45           
  Lines        5154     5154           
=======================================
  Hits         4908     4908           
  Misses        246      246           
Flag Coverage Δ
integration 95.22% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The billing endpoint body was built with `count or 1`, which silently
rewrote a legitimate `count=0` to `count=1` — on a pay-per-event
endpoint, the difference is financially material. Use an explicit
`None` check instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vdusek vdusek force-pushed the fix/run-charge-preserve-zero-count branch from 463e742 to 0faf061 Compare April 22, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants