@@ -193,19 +193,12 @@ def apify_client(self) -> ApifyClientAsync:
193
193
self ._apify_client = self .new_client ()
194
194
return self ._apify_client
195
195
196
- @property
196
+ @cached_property
197
197
def configuration (self ) -> Configuration :
198
198
"""The Configuration instance the Actor instance uses."""
199
199
if self ._configuration :
200
200
return self ._configuration
201
201
202
- return self ._finalize_implicit_configuration ()
203
-
204
- def _finalize_implicit_configuration (self ) -> Configuration :
205
- """Set implicit configuration in the Actor and return it.
206
-
207
- Changing Actor or service_locator configuration after this method was run is not possible.
208
- """
209
202
try :
210
203
# Set implicit default Apify configuration, unless configuration was already set.
211
204
implicit_configuration = Configuration ()
@@ -216,34 +209,10 @@ def _finalize_implicit_configuration(self) -> Configuration:
216
209
'Configuration in service locator was set explicitly before Actor.init was called.'
217
210
'Using the existing configuration as implicit configuration for the Actor.'
218
211
)
212
+
219
213
# Use the configuration from the service locator
220
214
self ._configuration = Configuration .get_global_configuration ()
221
- return self .configuration
222
-
223
- def _finalize_implicit_local_storage_client (self ) -> StorageClient :
224
- """Set implicit local storage client in the Actor and return it.
225
-
226
- Changing Actor or service_locator storage client after this method was run is not possible.
227
- """
228
- try :
229
- # Set implicit default local storage client, unless local storage client was already set.
230
- implicit_storage_client = ApifyFileSystemStorageClient ()
231
- service_locator .set_storage_client (implicit_storage_client )
232
- self ._local_storage_client = implicit_storage_client
233
- except ServiceConflictError :
234
- self .log .debug (
235
- 'Storage client in service locator was set explicitly before Actor.init was called.'
236
- 'Using the existing storage client as implicit storage client for the Actor.'
237
- )
238
-
239
- self ._local_storage_client = service_locator .get_storage_client ()
240
- if type (self ._local_storage_client ) is FileSystemStorageClient :
241
- self .log .warning (
242
- f'Using { FileSystemStorageClient .__module__ } .{ FileSystemStorageClient .__name__ } in Actor context is not'
243
- f' recommended and can lead to problems with reading the input file. Use '
244
- f'`apify.storage_clients.FileSystemStorageClient` instead.'
245
- )
246
- return self ._local_storage_client
215
+ return self ._configuration
247
216
248
217
@cached_property
249
218
def event_manager (self ) -> EventManager :
@@ -269,7 +238,27 @@ def _get_local_storage_client(self) -> StorageClient:
269
238
"""Get the local storage client the Actor instance uses."""
270
239
if self ._local_storage_client :
271
240
return self ._local_storage_client
272
- return self ._finalize_implicit_local_storage_client ()
241
+
242
+ try :
243
+ # Set implicit default local storage client, unless local storage client was already set.
244
+ implicit_storage_client = ApifyFileSystemStorageClient ()
245
+ service_locator .set_storage_client (implicit_storage_client )
246
+ self ._local_storage_client = implicit_storage_client
247
+ except ServiceConflictError :
248
+ self .log .debug (
249
+ 'Storage client in service locator was set explicitly before Actor.init was called.'
250
+ 'Using the existing storage client as implicit storage client for the Actor.'
251
+ )
252
+
253
+ self ._local_storage_client = service_locator .get_storage_client ()
254
+ if type (self ._local_storage_client ) is FileSystemStorageClient :
255
+ self .log .warning (
256
+ f'Using { FileSystemStorageClient .__module__ } .{ FileSystemStorageClient .__name__ } in Actor context is not'
257
+ f' recommended and can lead to problems with reading the input file. Use '
258
+ f'`apify.storage_clients.FileSystemStorageClient` instead.'
259
+ )
260
+
261
+ return self ._local_storage_client
273
262
274
263
def _raise_if_not_initialized (self ) -> None :
275
264
if not self ._is_initialized :
@@ -300,7 +289,8 @@ async def init(self) -> None:
300
289
# Set explicitly the configuration in the service locator
301
290
service_locator .set_configuration (self .configuration )
302
291
else :
303
- self ._finalize_implicit_configuration ()
292
+ # Ensure that the configuration (cached property) is set
293
+ _ = self .configuration
304
294
305
295
if self ._is_initialized :
306
296
raise RuntimeError ('The Actor was already initialized!' )
@@ -323,7 +313,8 @@ async def init(self) -> None:
323
313
service_locator .set_storage_client (self ._cloud_storage_client )
324
314
self ._local_storage_client = self ._cloud_storage_client
325
315
else :
326
- self ._finalize_implicit_local_storage_client ()
316
+ self ._get_local_storage_client ()
317
+
327
318
service_locator .set_event_manager (self .event_manager )
328
319
329
320
# The logging configuration has to be called after all service_locator set methods.
@@ -522,6 +513,7 @@ async def open_key_value_store(
522
513
"""
523
514
self ._raise_if_not_initialized ()
524
515
self ._raise_if_cloud_requested_but_not_configured (force_cloud = force_cloud )
516
+
525
517
storage_client = self ._cloud_storage_client if force_cloud else self ._get_local_storage_client ()
526
518
527
519
return await KeyValueStore .open (
0 commit comments