Skip to content

Commit 915cb46

Browse files
authored
fix(python): add warning in replace_all_objects for empty objects (#6611)
1 parent ea8de3b commit 915cb46

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎templates/python/search_helpers.mustache‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,18 @@
432432
Helper: Similar to the `replaceAllObjects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. `transformation_options` must be set on `SearchConfig` before creating the client, or via `client.set_transformation_options(...)`.
433433
434434
See https://api-clients-automation.netlify.app/docs/custom-helpers/#replaceallobjects for implementation details.
435+
436+
Warning: calling this method with an empty `objects` list replaces the index with an empty one, deleting all existing records.
435437
"""
436438
if self._ingestion_transporter is None:
437439
raise ValueError("`transformation_options` must be set on `SearchConfig` before creating the client, or via `client.set_transformation_options(...)` before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/")
440+
from collections.abc import Sized
441+
import logging
442+
443+
if isinstance(objects, Sized) and len(objects) == 0:
444+
logging.getLogger(__name__).warning(
445+
f'replace_all_objects_with_transformation was called with an empty list of objects, which will delete all records currently in the "{index_name}" index.'
446+
)
438447
chunked_options = chunked_options or ChunkedHelperOptions(max_retries=ChunkedHelperOptions.DEFAULT_REPLACE_ALL_OBJECTS_MAX_RETRIES)
439448
tmp_index_name = self.create_temporary_name(index_name)
440449
@@ -508,7 +517,16 @@
508517
Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
509518
510519
See https://api-clients-automation.netlify.app/docs/custom-helpers/#replaceallobjects for implementation details.
520+
521+
Warning: calling this method with an empty `objects` list replaces the index with an empty one, deleting all existing records.
511522
"""
523+
from collections.abc import Sized
524+
import logging
525+
526+
if isinstance(objects, Sized) and len(objects) == 0:
527+
logging.getLogger(__name__).warning(
528+
f'replace_all_objects was called with an empty list of objects, which will delete all records currently in the "{index_name}" index.'
529+
)
512530
chunked_options = chunked_options or ChunkedHelperOptions(max_retries=ChunkedHelperOptions.DEFAULT_REPLACE_ALL_OBJECTS_MAX_RETRIES)
513531
tmp_index_name = self.create_temporary_name(index_name)
514532

0 commit comments

Comments
 (0)