Skip to content

Commit 94269ef

Browse files
committed
Update
1 parent 4127bcf commit 94269ef

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

src/apify/_charging.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,21 @@ async def _fetch_pricing_info(self) -> _FetchedPricingInfoDict:
351351
if self._actor_run_id is None:
352352
raise RuntimeError('Actor run ID not found even though the Actor is running on Apify')
353353

354-
run = run_validator.validate_python(await self._client.run(self._actor_run_id).get())
354+
run = await self._client.run(self._actor_run_id).get()
355+
355356
if run is None:
356357
raise RuntimeError('Actor run not found')
357358

359+
run_dict = run.model_dump(by_alias=True)
360+
actor_run = run_validator.validate_python(run_dict)
361+
362+
if actor_run is None:
363+
raise RuntimeError('Actor run not found')
364+
358365
return _FetchedPricingInfoDict(
359-
pricing_info=run.pricing_info,
360-
charged_event_counts=run.charged_event_counts or {},
361-
max_total_charge_usd=run.options.max_total_charge_usd or Decimal('inf'),
366+
pricing_info=actor_run.pricing_info,
367+
charged_event_counts=actor_run.charged_event_counts or {},
368+
max_total_charge_usd=actor_run.options.max_total_charge_usd or Decimal('inf'),
362369
)
363370

364371
# Local development without environment variables

tests/integration/actor/conftest.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,11 @@ async def _make_actor(
256256

257257
# Delete all the generated Actors.
258258
for actor_id in actors_for_cleanup:
259-
actor_client = ApifyClient(token=apify_token, api_url=os.getenv(_API_URL_ENV_VAR)).actor(actor_id)
259+
apify_client = ApifyClient(token=apify_token, api_url=os.getenv(_API_URL_ENV_VAR))
260+
actor_client = apify_client.actor(actor_id)
261+
actor = actor_client.get()
260262

261-
if (actor := actor_client.get()) is not None:
262-
assert actor.pricing_infos is not None
263+
if actor is not None and actor.pricing_infos is not None:
263264
new_pricing_infos = [*actor.pricing_infos, {'pricingModel': 'FREE'}]
264265
actor_client.update(pricing_infos=new_pricing_infos)
265266

@@ -301,17 +302,16 @@ async def _run_actor(
301302
run_input: Any = None,
302303
max_total_charge_usd: Decimal | None = None,
303304
) -> ActorRun:
304-
call_result = await actor.call(
305-
run_input=run_input,
306-
max_total_charge_usd=max_total_charge_usd,
307-
)
305+
call_result = await actor.call(run_input=run_input, max_total_charge_usd=max_total_charge_usd)
306+
307+
assert call_result is not None, 'Failed to start Actor run: missing run ID in the response.'
308308

309-
assert isinstance(call_result, dict), 'The result of ActorClientAsync.call() is not a dictionary.'
310-
assert 'id' in call_result, 'The result of ActorClientAsync.call() does not contain an ID.'
309+
run_client = apify_client_async.run(call_result.id)
310+
actor_run = await run_client.wait_for_finish(wait_secs=600)
311311

312-
run_client = apify_client_async.run(call_result['id'])
313-
run_result = await run_client.wait_for_finish(wait_secs=600)
312+
assert actor_run is not None, 'Actor run did not finish successfully within the expected time.'
314313

315-
return ActorRun.model_validate(run_result)
314+
actor_run_dict = actor_run.model_dump(by_alias=True)
315+
return ActorRun.model_validate(actor_run_dict)
316316

317317
return _run_actor

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)