Skip to content

Commit 5bf51f7

Browse files
committed
Add warning for usage of FileSystemStorageClient in Actor context
1 parent 6fbb5f4 commit 5bf51f7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/apify/_actor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
EventPersistStateData,
2626
EventSystemInfoData,
2727
)
28+
from crawlee.storage_clients import FileSystemStorageClient
2829

2930
from apify._charging import ChargeResult, ChargingManager, ChargingManagerImplementation
3031
from apify._configuration import Configuration
@@ -244,7 +245,13 @@ def _finalize_implicit_local_storage_client(self) -> StorageClient:
244245
'Storage client in service locator was set explicitly before Actor.init was called.'
245246
'Using the existing storage client as implicit storage client for the Actor.'
246247
)
248+
247249
self._local_storage_client = service_locator.get_storage_client()
250+
if type(self._local_storage_client) is FileSystemStorageClient:
251+
self.log.warning(
252+
'Using `FileSystemStorageClient` in Actor context is not recommended and can lead to '
253+
'problems with reading the input file. Use `ApifyFileSystemStorageClient` instead.'
254+
)
248255
return self._local_storage_client
249256

250257
@property

tests/unit/actor/test_configuration.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from crawlee.configuration import Configuration as CrawleeConfiguration
88
from crawlee.crawlers import BasicCrawler
99
from crawlee.errors import ServiceConflictError
10+
from crawlee.storage_clients import FileSystemStorageClient
1011

1112
from apify import Actor
1213
from apify import Configuration as ApifyConfiguration
@@ -215,3 +216,15 @@ async def test_storage_retrieved_is_same_with_same_config() -> None:
215216
crawler_kvs = await crawler.get_key_value_store()
216217

217218
assert actor_kvs is crawler_kvs
219+
220+
221+
async def test_file_system_storage_client_warning(caplog: pytest.LogCaptureFixture) -> None:
222+
service_locator.set_storage_client(FileSystemStorageClient())
223+
caplog.set_level('WARNING')
224+
async with Actor():
225+
...
226+
227+
assert (
228+
'Using `FileSystemStorageClient` in Actor context is not recommended and can lead to problems with reading '
229+
'the input file. Use `ApifyFileSystemStorageClient` instead.'
230+
) in caplog.messages

0 commit comments

Comments
 (0)