Skip to content

Commit b481352

Browse files
committed
Sanitize input files on open(), not purge()
1 parent 9843ab8 commit b481352

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/apify/storage_clients/_file_system/_key_value_store_client.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import logging
44

55
from more_itertools import flatten
6-
from typing_extensions import override
6+
from typing_extensions import Self, override
77

88
from crawlee._consts import METADATA_FILENAME
9+
from crawlee.configuration import Configuration as CrawleeConfiguration
910
from crawlee.storage_clients._file_system import FileSystemKeyValueStoreClient
1011
from crawlee.storage_clients.models import KeyValueStoreRecord
1112

@@ -21,6 +22,22 @@ class ApifyFileSystemKeyValueStoreClient(FileSystemKeyValueStoreClient):
2122
directory, except for the metadata file and the `INPUT.json` file.
2223
"""
2324

25+
@override
26+
@classmethod
27+
async def open(
28+
cls,
29+
*,
30+
id: str | None,
31+
name: str | None,
32+
alias: str | None,
33+
configuration: CrawleeConfiguration,
34+
) -> Self:
35+
client = await super().open(id=id, name=name, alias=alias, configuration=configuration)
36+
37+
await client._sanitize_input_json_files() # noqa: SLF001 - it's okay, this is a factory method
38+
39+
return client
40+
2441
@override
2542
async def purge(self) -> None:
2643
"""Purges the key-value store by deleting all its contents.
@@ -30,8 +47,6 @@ async def purge(self) -> None:
3047
"""
3148
configuration = Configuration.get_global_configuration()
3249

33-
await self._sanitize_input_json_files()
34-
3550
async with self._lock:
3651
files_to_keep = set(
3752
flatten([key, f'{key}.{METADATA_FILENAME}'] for key in configuration.input_key_candidates)

0 commit comments

Comments
 (0)