Skip to content

Commit 3e77cca

Browse files
committed
fix: Make sure that Actor instances with non-default configurations are also accessible through the global Actor proxy after initialization
1 parent 9706c94 commit 3e77cca

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/apify/_actor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ async def init(self) -> None:
200200
if self._is_initialized:
201201
raise RuntimeError('The Actor was already initialized!')
202202

203+
# Make sure that the currently initialized instance is also available through the global `Actor` proxy
204+
cast(Proxy, Actor).__wrapped__ = self
205+
203206
self._is_exiting = False
204207
self._was_final_persist_state_emitted = False
205208

tests/unit/actor/test_actor_lifecycle.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import apify._actor
1717
from apify import Actor
1818
from apify._actor import _ActorType
19+
from apify._configuration import Configuration
1920

2021

2122
async def test_actor_properly_init_with_async() -> None:
@@ -35,6 +36,13 @@ async def test_actor_init() -> None:
3536
assert my_actor._is_initialized is False
3637

3738

39+
async def test_actor_global_works() -> None:
40+
non_default_configuration = Configuration(actor_full_name='Actor McActorson, esq.')
41+
42+
async with Actor(configuration=non_default_configuration):
43+
assert Actor.configuration is non_default_configuration
44+
45+
3846
async def test_double_init_raises_error(prepare_test_env: Callable) -> None:
3947
async with Actor:
4048
assert Actor._is_initialized

0 commit comments

Comments
 (0)