From be14b4ce6dc05635647b7f6eeee097900ae74545 Mon Sep 17 00:00:00 2001 From: Josef Prochazka Date: Tue, 10 Mar 2026 17:02:14 +0100 Subject: [PATCH 1/3] Test reading default from config --- src/apify/storage_clients/_apify/_alias_resolving.py | 2 +- src/apify/storage_clients/_apify/_api_client_creation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apify/storage_clients/_apify/_alias_resolving.py b/src/apify/storage_clients/_apify/_alias_resolving.py index 1170193b..98a35bc4 100644 --- a/src/apify/storage_clients/_apify/_alias_resolving.py +++ b/src/apify/storage_clients/_apify/_alias_resolving.py @@ -195,7 +195,7 @@ async def resolve_id(self) -> str | None: """ # First try to find the alias in the configuration mapping to avoid any API calls. # This mapping is maintained by the Apify platform and does not have to be maintained in the default KVS. - if self._configuration.actor_storages and self._alias != 'default': + if self._configuration.actor_storages: storage_maps = { 'Dataset': self._configuration.actor_storages['datasets'], 'KeyValueStore': self._configuration.actor_storages['key_value_stores'], diff --git a/src/apify/storage_clients/_apify/_api_client_creation.py b/src/apify/storage_clients/_apify/_api_client_creation.py index 39e2a087..26fd26d4 100644 --- a/src/apify/storage_clients/_apify/_api_client_creation.py +++ b/src/apify/storage_clients/_apify/_api_client_creation.py @@ -111,7 +111,7 @@ def get_resource_client(storage_id: str) -> DatasetClientAsync: # Handle different opening scenarios match (alias, name, id, default_id): # Normalize unnamed default storage to unnamed storage aliased as `__default__`. - case (None, None, None, None): + case (None | 'default', None, None, None): return await open_by_alias( alias='__default__', storage_type=storage_type, From 7efd37f3f67b740e0262206d9fe77bcd250604bc Mon Sep 17 00:00:00 2001 From: Josef Prochazka Date: Wed, 11 Mar 2026 16:27:23 +0100 Subject: [PATCH 2/3] There is no need for `__default__` --- src/apify/storage_clients/_apify/_alias_resolving.py | 4 +++- src/apify/storage_clients/_apify/_api_client_creation.py | 6 +++--- tests/integration/test_storages.py | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/apify/storage_clients/_apify/_alias_resolving.py b/src/apify/storage_clients/_apify/_alias_resolving.py index 98a35bc4..d5910da7 100644 --- a/src/apify/storage_clients/_apify/_alias_resolving.py +++ b/src/apify/storage_clients/_apify/_alias_resolving.py @@ -76,7 +76,7 @@ async def open_by_alias( The alias mapping is stored in the default key-value store for persistence across Actor runs. Args: - alias: The alias name for the storage (e.g., '__default__', 'my-storage'). + alias: The alias name for the storage (e.g., 'my-storage'). storage_type: The type of storage to open. collection_client: The Apify API collection client for the storage type. get_resource_client_by_id: A callable that takes a storage ID and returns the resource client. @@ -131,6 +131,8 @@ class AliasResolver: _alias_init_lock: Lock | None = None """Lock for creating alias storages. Only one alias storage can be created at the time. Global for all instances.""" + default_storage_key: ClassVar[str] = '__default_unnamed__' + def __init__( self, storage_type: Literal['Dataset', 'KeyValueStore', 'RequestQueue'], diff --git a/src/apify/storage_clients/_apify/_api_client_creation.py b/src/apify/storage_clients/_apify/_api_client_creation.py index 26fd26d4..542a203f 100644 --- a/src/apify/storage_clients/_apify/_api_client_creation.py +++ b/src/apify/storage_clients/_apify/_api_client_creation.py @@ -5,7 +5,7 @@ from apify_client import ApifyClientAsync from crawlee._utils.crypto import crypto_random_object_id -from apify.storage_clients._apify._alias_resolving import open_by_alias +from apify.storage_clients._apify._alias_resolving import AliasResolver, open_by_alias if TYPE_CHECKING: from apify_client.clients import DatasetClientAsync, KeyValueStoreClientAsync, RequestQueueClientAsync @@ -111,9 +111,9 @@ def get_resource_client(storage_id: str) -> DatasetClientAsync: # Handle different opening scenarios match (alias, name, id, default_id): # Normalize unnamed default storage to unnamed storage aliased as `__default__`. - case (None | 'default', None, None, None): + case (None, None, None, None): return await open_by_alias( - alias='__default__', + alias=AliasResolver.default_storage_key, storage_type=storage_type, collection_client=collection_client, get_resource_client_by_id=get_resource_client, diff --git a/tests/integration/test_storages.py b/tests/integration/test_storages.py index 7ad807fe..d09036d8 100644 --- a/tests/integration/test_storages.py +++ b/tests/integration/test_storages.py @@ -9,6 +9,7 @@ from apify import Actor, Configuration from apify.storage_clients import ApifyStorageClient, MemoryStorageClient, SmartApifyStorageClient +from apify.storage_clients._apify._alias_resolving import AliasResolver @pytest.mark.parametrize( @@ -125,3 +126,11 @@ async def test_actor_implicit_storage_init(apify_token: str) -> None: assert await Actor.open_dataset() is not await Actor.open_dataset(force_cloud=True) assert await Actor.open_key_value_store() is not await Actor.open_key_value_store(force_cloud=True) assert await Actor.open_request_queue() is not await Actor.open_request_queue(force_cloud=True) + + +async def test_default_storage(apify_token: str) -> None: + service_locator.set_configuration(Configuration(token=apify_token)) + async with Actor: + dataset_1 = await Actor.open_dataset(force_cloud=True) + dataset_2 = await Actor.open_dataset(force_cloud=True, alias=AliasResolver.default_storage_key) + assert dataset_1.id == dataset_2.id From 082100db911efb183ec906160dfba9453ddb4312 Mon Sep 17 00:00:00 2001 From: Josef Prochazka Date: Fri, 13 Mar 2026 11:34:18 +0100 Subject: [PATCH 3/3] Update e2e tests --- src/apify/storage_clients/_apify/_alias_resolving.py | 2 +- tests/e2e/test_schema_storages/actor_source/main.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/apify/storage_clients/_apify/_alias_resolving.py b/src/apify/storage_clients/_apify/_alias_resolving.py index d5910da7..c07edca3 100644 --- a/src/apify/storage_clients/_apify/_alias_resolving.py +++ b/src/apify/storage_clients/_apify/_alias_resolving.py @@ -131,7 +131,7 @@ class AliasResolver: _alias_init_lock: Lock | None = None """Lock for creating alias storages. Only one alias storage can be created at the time. Global for all instances.""" - default_storage_key: ClassVar[str] = '__default_unnamed__' + default_storage_key: ClassVar[str] = '__default__' def __init__( self, diff --git a/tests/e2e/test_schema_storages/actor_source/main.py b/tests/e2e/test_schema_storages/actor_source/main.py index 43a82207..454d3bf7 100644 --- a/tests/e2e/test_schema_storages/actor_source/main.py +++ b/tests/e2e/test_schema_storages/actor_source/main.py @@ -7,3 +7,7 @@ async def main() -> None: dataset = await Actor.open_dataset(alias='custom') expected_id = Actor.configuration.actor_storages['datasets']['custom'] assert dataset.id == expected_id + + implicit_default_dataset = await Actor.open_dataset() + explicit_default_dataset = await Actor.open_dataset(alias='default') + assert implicit_default_dataset.id == explicit_default_dataset.id