@@ -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
0 commit comments