Skip to content

Commit 3062146

Browse files
committed
There is no need for default
1 parent be14b4c commit 3062146

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/apify/storage_clients/_apify/_alias_resolving.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def open_by_alias(
7676
The alias mapping is stored in the default key-value store for persistence across Actor runs.
7777
7878
Args:
79-
alias: The alias name for the storage (e.g., '__default__', 'my-storage').
79+
alias: The alias name for the storage (e.g., 'my-storage').
8080
storage_type: The type of storage to open.
8181
collection_client: The Apify API collection client for the storage type.
8282
get_resource_client_by_id: A callable that takes a storage ID and returns the resource client.
@@ -131,6 +131,8 @@ class AliasResolver:
131131
_alias_init_lock: Lock | None = None
132132
"""Lock for creating alias storages. Only one alias storage can be created at the time. Global for all instances."""
133133

134+
default_storage_key: ClassVar[str] = '__default_unnamed__'
135+
134136
def __init__(
135137
self,
136138
storage_type: Literal['Dataset', 'KeyValueStore', 'RequestQueue'],

src/apify/storage_clients/_apify/_api_client_creation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from apify_client import ApifyClientAsync
66
from crawlee._utils.crypto import crypto_random_object_id
77

8-
from apify.storage_clients._apify._alias_resolving import open_by_alias
8+
from apify.storage_clients._apify._alias_resolving import AliasResolver, open_by_alias
99

1010
if TYPE_CHECKING:
1111
from apify_client.clients import DatasetClientAsync, KeyValueStoreClientAsync, RequestQueueClientAsync
@@ -111,9 +111,9 @@ def get_resource_client(storage_id: str) -> DatasetClientAsync:
111111
# Handle different opening scenarios
112112
match (alias, name, id, default_id):
113113
# Normalize unnamed default storage to unnamed storage aliased as `__default__`.
114-
case (None | 'default', None, None, None):
114+
case (None, None, None, None):
115115
return await open_by_alias(
116-
alias='__default__',
116+
alias=AliasResolver.default_storage_key,
117117
storage_type=storage_type,
118118
collection_client=collection_client,
119119
get_resource_client_by_id=get_resource_client,

tests/integration/test_storages.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from apify import Actor, Configuration
1111
from apify.storage_clients import ApifyStorageClient, MemoryStorageClient, SmartApifyStorageClient
12+
from apify.storage_clients._apify._alias_resolving import AliasResolver
1213

1314

1415
@pytest.mark.parametrize(
@@ -125,3 +126,11 @@ async def test_actor_implicit_storage_init(apify_token: str) -> None:
125126
assert await Actor.open_dataset() is not await Actor.open_dataset(force_cloud=True)
126127
assert await Actor.open_key_value_store() is not await Actor.open_key_value_store(force_cloud=True)
127128
assert await Actor.open_request_queue() is not await Actor.open_request_queue(force_cloud=True)
129+
130+
131+
async def test_default_storage(apify_token: str) -> None:
132+
service_locator.set_configuration(Configuration(token=apify_token))
133+
async with Actor:
134+
dataset_1 = await Actor.open_dataset(force_cloud=True)
135+
dataset_2 = await Actor.open_dataset(force_cloud=True, alias=AliasResolver.default_storage_key)
136+
assert dataset_1.id == dataset_2.id

0 commit comments

Comments
 (0)