fix: allow Actor.newClient().dataset() without Actor.init()#653
Merged
Conversation
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()`).
|
See more at https://github.com/apify/apify-sdk-js/actions/runs/28433382917#summary-84253273229 |
barjin
approved these changes
Jun 30, 2026
Member
Author
|
The tests are pretty flaky, rerun succeeded, so merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The charging-aware client returned by
Actor.newClient()throwsError: ChargingManager is not initializedfrom itsdataset()getter whenActor.init()hasn't been called:PatchedApifyClient.dataset()always evaluatedactor.getChargingManager().getPricingInfo(), andgetPricingInfo()throws when the manager isn't initialized. But the docs stateActor.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 viaActor.newClient()withoutinit()).Fix
Mirror the guard the SDK already applies in the
pushDatacharging path (Actor.pushData()works withoutinit()— charging just isn't configured): only apply charging interception when theChargingManageris initialized; otherwise return a plainDatasetClient.ChargingManager.isInitialized(mirrors the existingchargingState === undefinedguards) and gate the interception on it.getChargingManager(). The public getter also logs a misleading "did you forget Actor.init()?" warning on this supported path and latcheswarnedAboutMissingInitCall, which would make a subsequentActor.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 callingActor.init()) that asserts no throw and no spurious init warning.