Skip to content

fix: allow Actor.newClient().dataset() without Actor.init()#653

Merged
B4nan merged 1 commit into
masterfrom
fix/newclient-dataset-without-init
Jun 30, 2026
Merged

fix: allow Actor.newClient().dataset() without Actor.init()#653
B4nan merged 1 commit into
masterfrom
fix/newclient-dataset-without-init

Conversation

@B4nan

@B4nan B4nan commented Jun 30, 2026

Copy link
Copy Markdown
Member

What & why

The charging-aware client returned by Actor.newClient() throws Error: ChargingManager is not initialized from its dataset() getter when Actor.init() hasn't been called:

const client = Actor.newClient({ token });
client.dataset(someId); // 💥 ChargingManager is not initialized

PatchedApifyClient.dataset() always evaluated actor.getChargingManager().getPricingInfo(), and getPricingInfo() throws when the manager isn't initialized. But the docs state Actor.init() is only required on the platform, so a standalone client should work. This regressed standalone usage (it surfaced in Crawlee's e2e harness, which reads dataset results via Actor.newClient() without init()).

Fix

Mirror the guard the SDK already applies in the pushData charging path (Actor.pushData() works without init() — charging just isn't configured): only apply charging interception when the ChargingManager is initialized; otherwise return a plain DatasetClient.

  • Add ChargingManager.isInitialized (mirrors the existing chargingState === undefined guards) and gate the interception on it.
  • Hand the patched client the raw manager instead of the public getChargingManager(). The public getter also logs a misleading "did you forget Actor.init()?" warning on this supported path and latches warnedAboutMissingInitCall, which would make a subsequent Actor.init() throw.

When initialized (platform run, PPE pricing, default dataset) behavior is unchanged — the existing charging suite passes.

Test

Added a regression test (dataset() works without calling Actor.init()) that asserts no throw and no spurious init warning.

The charging-aware client returned by `Actor.newClient()` threw
`ChargingManager is not initialized` from its `dataset()` getter when
`Actor.init()` had not been called, because it always invoked
`getChargingManager().getPricingInfo()`. The docs state `init()` is only
required on the platform, so a standalone client must work — this was a
regression.

Mirror the guard the SDK already applies in the pushData charging path:
only intercept for charging when the ChargingManager is initialized,
otherwise return a plain DatasetClient. Gate on a new
`ChargingManager.isInitialized` getter, and hand the patched client the
raw manager (not the public `getChargingManager()`, which also logs a
misleading "did you forget Actor.init()?" warning and latches
`warnedAboutMissingInitCall`, breaking a later `init()`).
@B4nan B4nan added the adhoc Ad-hoc unplanned task added during the sprint. label Jun 30, 2026
@github-actions

Copy link
Copy Markdown

⚠️ There are broken links in the documentation.

See more at https://github.com/apify/apify-sdk-js/actions/runs/28433382917#summary-84253273229

@B4nan B4nan requested review from barjin and janbuchar June 30, 2026 09:34

@janbuchar janbuchar left a comment

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.

If E2E tests succeed, I think it's good to go. I do look forward to replacing this with something sane in v4.

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, thanks @B4nan 👍

@B4nan

B4nan commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

The tests are pretty flaky, rerun succeeded, so merging.

@B4nan B4nan merged commit 4f151b3 into master Jun 30, 2026
9 of 10 checks passed
@B4nan B4nan deleted the fix/newclient-dataset-without-init branch June 30, 2026 11:57
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants