Skip to content

fix: preserve max_total_charge_usd=0 instead of treating it as unlimited#870

Merged
vdusek merged 2 commits intomasterfrom
fix/max-total-charge-usd-zero-preserved
Apr 20, 2026
Merged

fix: preserve max_total_charge_usd=0 instead of treating it as unlimited#870
vdusek merged 2 commits intomasterfrom
fix/max-total-charge-usd-zero-preserved

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented Apr 20, 2026

Summary

configuration.max_total_charge_usd or Decimal('inf') at src/apify/_charging.py:162, :416, and :439 treats Decimal(0) as falsy and silently replaces it with Decimal('inf'). A user who explicitly sets max_total_charge_usd=0 (or ACTOR_MAX_TOTAL_CHARGE_USD=0) to disable charging ends up with unlimited charging — the opposite of the intended behavior.

The configuration layer already preserves 0 as a distinct value (and test_max_total_charge_usd_zero_is_preserved asserts this), so the invariant is thrown away only at the charging manager boundary.

Replaced the three occurrences with an explicit … if … is not None else Decimal('inf') check, matching the already-correct pattern used on the API-fetch path (line 438).

🤖 Generated with Claude Code

…mited

`Decimal(0) or Decimal('inf')` evaluates to `Decimal('inf')` because
`Decimal(0)` is falsy, silently inverting the user's intent when `0` is
explicitly set as a kill-switch. Replace with an explicit `is not None`
check at the three affected sites, matching the correct pattern already
used on the API-fetch path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@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 20, 2026
@vdusek vdusek self-assigned this Apr 20, 2026
@github-actions github-actions Bot added this to the 139th sprint - Tooling team milestone Apr 20, 2026
@vdusek vdusek requested a review from Pijukatel April 20, 2026 12:42
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.64%. Comparing base (16bf07d) to head (ce7bcbd).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #870   +/-   ##
=======================================
  Coverage   86.64%   86.64%           
=======================================
  Files          48       48           
  Lines        2920     2920           
=======================================
  Hits         2530     2530           
  Misses        390      390           
Flag Coverage Δ
e2e 37.87% <0.00%> (ø)
integration 59.28% <100.00%> (ø)
unit 75.37% <100.00%> (+0.68%) ⬆️

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.

Copy link
Copy Markdown
Contributor

@Pijukatel Pijukatel left a comment

Choose a reason for hiding this comment

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

Good catch, I think this deserves a test.

Add two regression tests matching the three fix sites in
`ChargingManagerImplementation`:

- with PPE pricing env vars set, `max_total_charge_usd=0` blocks all
  charging (exercises `__init__` + the env-var `_fetch_pricing_info`
  path).
- without pricing, the zero value is still preserved through the
  fallback path.

Both would have failed before the fix (the `or Decimal('inf')`
coalescence silently promoted `Decimal(0)` to unlimited).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Apr 20, 2026
@vdusek vdusek merged commit 714334c into master Apr 20, 2026
29 checks passed
@vdusek vdusek deleted the fix/max-total-charge-usd-zero-preserved branch April 20, 2026 14:01
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