@@ -263,38 +263,40 @@ async def _get_default_kvs_client(configuration: Configuration) -> KeyValueStore
263263
264264 return apify_client_async .key_value_store (key_value_store_id = configuration .default_key_value_store_id )
265265
266-
267266 @classmethod
268267 async def register_aliases (cls , configuration : Configuration ) -> None :
269- """Load alias mapping from dictionary to the default kvs."""
270- def convert_name (name : str ):
271- """Convert from mapping name to storage type name used in the alias mapping."""
272- return {"datasets" : "Dataset" , "keyValueStores" : "KeyValueStore" , "requestQueues" : "RequestQueue" }[name ]
273-
268+ """Load any alias mapping from configuration to the default kvs."""
269+ if configuration .actor_storages is None :
270+ return
274271 configuration_mapping = {}
275272
276- if configuration .default_dataset_id != configuration .actor_storages ["datasets" ].get ("default" , configuration .default_dataset_id ):
277- raise RuntimeError (
278- f"Conflicting default dataset ids: { configuration .default_dataset_id = } ,"
279- f" { configuration .actor_storages ['datasets' ].get ('default' )= } " )
273+ if configuration .default_dataset_id != configuration .actor_storages .datasets .get (
274+ 'default' ):
275+ logger .warning (
276+ f'Conflicting default dataset ids: { configuration .default_dataset_id = } ,'
277+ f" { configuration .actor_storages .datasets .get ('default' )= } "
278+ )
280279
281- for config_storage_type , mapping in configuration .actor_storages .items ():
280+ for mapping , storage_type in (
281+ (configuration .actor_storages .key_value_stores , 'KeyValueStore' ),
282+ (configuration .actor_storages .datasets , 'Dataset' ),
283+ (configuration .actor_storages .request_queues , 'RequestQueue' ),
284+ ):
282285 for storage_alias , storage_id in mapping .items ():
283- if storage_alias == "default" :
284- # This is how the default storage is stored in the default kvs
285- storage_alias = "__default__"
286-
287- configuration_mapping [AliasResolver (
288- storage_type = convert_name (config_storage_type ),
289- alias = storage_alias ,
290- configuration = configuration ,
291- )._storage_key ] = storage_id
286+ configuration_mapping [
287+ cls ( # noqa: SLF001# It is ok in own classmethod.
288+ storage_type = storage_type ,
289+ alias = '__default__' if storage_alias == 'default' else storage_alias ,
290+ configuration = configuration ,
291+ )._storage_key
292+ ] = storage_id
292293
293294 # Aliased storage can be also default storage!!!
294295 # Should we store such second alias to the default storage or ignore it in such case? Probably
295296
296297 # What if existing default dataset already has conflicting keys?
297298 # Just override it, that will teach it to have conflicting values!
298299 client = await cls ._get_default_kvs_client (configuration = configuration )
299- existing_mapping = (await client .get_record (cls ._ALIAS_MAPPING_KEY ) or {"value" :{}}).get ("value" )
300+ existing_mapping = ((await client .get_record (cls ._ALIAS_MAPPING_KEY )) or {'value' : {}}).get ('value' ,
301+ {})
300302 await client .set_record (cls ._ALIAS_MAPPING_KEY , {** existing_mapping , ** configuration_mapping })
0 commit comments