|
432 | 432 | 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(...)`. |
433 | 433 |
|
434 | 434 | 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. |
435 | 437 | """ |
436 | 438 | if self._ingestion_transporter is None: |
437 | 439 | 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 | + ) |
438 | 447 | chunked_options = chunked_options or ChunkedHelperOptions(max_retries=ChunkedHelperOptions.DEFAULT_REPLACE_ALL_OBJECTS_MAX_RETRIES) |
439 | 448 | tmp_index_name = self.create_temporary_name(index_name) |
440 | 449 |
|
|
508 | 517 | 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. |
509 | 518 |
|
510 | 519 | 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. |
511 | 522 | """ |
| 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 | + ) |
512 | 530 | chunked_options = chunked_options or ChunkedHelperOptions(max_retries=ChunkedHelperOptions.DEFAULT_REPLACE_ALL_OBJECTS_MAX_RETRIES) |
513 | 531 | tmp_index_name = self.create_temporary_name(index_name) |
514 | 532 |
|
|
0 commit comments