fix: Preserve count=0 in RunClient's charge by vdusek · Pull Request #751 · apify/apify-client-python · GitHub
Skip to content

fix: Preserve count=0 in RunClient's charge#751

Merged
vdusek merged 3 commits into
masterfrom
fix/run-charge-preserve-zero-count
Apr 27, 2026
Merged

fix: Preserve count=0 in RunClient's charge#751
vdusek merged 3 commits into
masterfrom
fix/run-charge-preserve-zero-count

Conversation

@vdusek

@vdusek vdusek commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

RunClient.charge (sync + async) built the request body with 'count': count or 1. Because or treats 0 as falsy, a caller passing count=0 — e.g. count=len(batch) for an empty batch, or a defensive no-op — was silently sent as count=1. On a pay-per-event billing endpoint that's a real overcharge, not a cosmetic bug.

Fix

Changed the signature from count: int | None = None to count: int = 1 and pass count through to the request body unchanged. 0 now reaches the server as 0; the default 1 is expressed in the signature instead of via a fallback.

Docstring updated to reflect the new contract.

Tests

tests/unit/test_run_charge.py parametrizes the sync and async clients over count values 0, 1, 5 and asserts the value lands in the request body verbatim. The 0 case fails on master and passes here.

@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

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why don't we fix it here?

count: int = 1,

Per review on PR #751, replace `count: int | None = None` + sentinel
check with a plain `count: int = 1` default, so `0` is preserved
naturally and the `None` branch disappears.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vdusek vdusek changed the title fix: preserve count=0 in RunClient.charge fix(run): preserve count=0 in RunClient.charge Apr 27, 2026
@vdusek vdusek changed the title fix(run): preserve count=0 in RunClient.charge fix: Preserve count=0 in RunClient's charge Apr 27, 2026
@vdusek vdusek requested a review from Pijukatel April 27, 2026 08:01
@vdusek vdusek merged commit 0a8942c into master Apr 27, 2026
26 checks passed
@vdusek vdusek deleted the fix/run-charge-preserve-zero-count branch April 27, 2026 08:08
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.

3 participants