@@ -620,57 +620,63 @@ async def replace_all_objects(
620
620
"""
621
621
tmp_index_name = self .create_temporary_name (index_name )
622
622
623
- async def _copy () -> UpdatedAtResponse :
624
- return await self .operation_index (
625
- index_name = index_name ,
626
- operation_index_params = OperationIndexParams (
627
- operation = OperationType .COPY ,
628
- destination = tmp_index_name ,
629
- scope = [
630
- ScopeType ("settings" ),
631
- ScopeType ("rules" ),
632
- ScopeType ("synonyms" ),
633
- ],
634
- ),
623
+ try :
624
+
625
+ async def _copy () -> UpdatedAtResponse :
626
+ return await self .operation_index (
627
+ index_name = index_name ,
628
+ operation_index_params = OperationIndexParams (
629
+ operation = OperationType .COPY ,
630
+ destination = tmp_index_name ,
631
+ scope = [
632
+ ScopeType ("settings" ),
633
+ ScopeType ("rules" ),
634
+ ScopeType ("synonyms" ),
635
+ ],
636
+ ),
637
+ request_options = request_options ,
638
+ )
639
+
640
+ copy_operation_response = await _copy ()
641
+
642
+ batch_responses = await self .chunked_batch (
643
+ index_name = tmp_index_name ,
644
+ objects = objects ,
645
+ wait_for_tasks = True ,
646
+ batch_size = batch_size ,
635
647
request_options = request_options ,
636
648
)
637
649
638
- copy_operation_response = await _copy ()
639
-
640
- batch_responses = await self .chunked_batch (
641
- index_name = tmp_index_name ,
642
- objects = objects ,
643
- wait_for_tasks = True ,
644
- batch_size = batch_size ,
645
- request_options = request_options ,
646
- )
650
+ await self .wait_for_task (
651
+ index_name = tmp_index_name , task_id = copy_operation_response .task_id
652
+ )
647
653
648
- await self .wait_for_task (
649
- index_name = tmp_index_name , task_id = copy_operation_response .task_id
650
- )
654
+ copy_operation_response = await _copy ()
655
+ await self .wait_for_task (
656
+ index_name = tmp_index_name , task_id = copy_operation_response .task_id
657
+ )
651
658
652
- copy_operation_response = await _copy ()
653
- await self .wait_for_task (
654
- index_name = tmp_index_name , task_id = copy_operation_response .task_id
655
- )
659
+ move_operation_response = await self .operation_index (
660
+ index_name = tmp_index_name ,
661
+ operation_index_params = OperationIndexParams (
662
+ operation = OperationType .MOVE ,
663
+ destination = index_name ,
664
+ ),
665
+ request_options = request_options ,
666
+ )
667
+ await self .wait_for_task (
668
+ index_name = tmp_index_name , task_id = move_operation_response .task_id
669
+ )
656
670
657
- move_operation_response = await self .operation_index (
658
- index_name = tmp_index_name ,
659
- operation_index_params = OperationIndexParams (
660
- operation = OperationType .MOVE ,
661
- destination = index_name ,
662
- ),
663
- request_options = request_options ,
664
- )
665
- await self .wait_for_task (
666
- index_name = tmp_index_name , task_id = move_operation_response .task_id
667
- )
671
+ return ReplaceAllObjectsResponse (
672
+ copy_operation_response = copy_operation_response ,
673
+ batch_responses = batch_responses ,
674
+ move_operation_response = move_operation_response ,
675
+ )
676
+ except Exception as e :
677
+ await self .delete_index (tmp_index_name )
668
678
669
- return ReplaceAllObjectsResponse (
670
- copy_operation_response = copy_operation_response ,
671
- batch_responses = batch_responses ,
672
- move_operation_response = move_operation_response ,
673
- )
679
+ raise e
674
680
675
681
async def index_exists (self , index_name : str ) -> bool :
676
682
"""
@@ -5658,57 +5664,63 @@ def replace_all_objects(
5658
5664
"""
5659
5665
tmp_index_name = self .create_temporary_name (index_name )
5660
5666
5661
- def _copy () -> UpdatedAtResponse :
5662
- return self .operation_index (
5663
- index_name = index_name ,
5664
- operation_index_params = OperationIndexParams (
5665
- operation = OperationType .COPY ,
5666
- destination = tmp_index_name ,
5667
- scope = [
5668
- ScopeType ("settings" ),
5669
- ScopeType ("rules" ),
5670
- ScopeType ("synonyms" ),
5671
- ],
5672
- ),
5667
+ try :
5668
+
5669
+ def _copy () -> UpdatedAtResponse :
5670
+ return self .operation_index (
5671
+ index_name = index_name ,
5672
+ operation_index_params = OperationIndexParams (
5673
+ operation = OperationType .COPY ,
5674
+ destination = tmp_index_name ,
5675
+ scope = [
5676
+ ScopeType ("settings" ),
5677
+ ScopeType ("rules" ),
5678
+ ScopeType ("synonyms" ),
5679
+ ],
5680
+ ),
5681
+ request_options = request_options ,
5682
+ )
5683
+
5684
+ copy_operation_response = _copy ()
5685
+
5686
+ batch_responses = self .chunked_batch (
5687
+ index_name = tmp_index_name ,
5688
+ objects = objects ,
5689
+ wait_for_tasks = True ,
5690
+ batch_size = batch_size ,
5673
5691
request_options = request_options ,
5674
5692
)
5675
5693
5676
- copy_operation_response = _copy ()
5677
-
5678
- batch_responses = self .chunked_batch (
5679
- index_name = tmp_index_name ,
5680
- objects = objects ,
5681
- wait_for_tasks = True ,
5682
- batch_size = batch_size ,
5683
- request_options = request_options ,
5684
- )
5694
+ self .wait_for_task (
5695
+ index_name = tmp_index_name , task_id = copy_operation_response .task_id
5696
+ )
5685
5697
5686
- self .wait_for_task (
5687
- index_name = tmp_index_name , task_id = copy_operation_response .task_id
5688
- )
5698
+ copy_operation_response = _copy ()
5699
+ self .wait_for_task (
5700
+ index_name = tmp_index_name , task_id = copy_operation_response .task_id
5701
+ )
5689
5702
5690
- copy_operation_response = _copy ()
5691
- self .wait_for_task (
5692
- index_name = tmp_index_name , task_id = copy_operation_response .task_id
5693
- )
5703
+ move_operation_response = self .operation_index (
5704
+ index_name = tmp_index_name ,
5705
+ operation_index_params = OperationIndexParams (
5706
+ operation = OperationType .MOVE ,
5707
+ destination = index_name ,
5708
+ ),
5709
+ request_options = request_options ,
5710
+ )
5711
+ self .wait_for_task (
5712
+ index_name = tmp_index_name , task_id = move_operation_response .task_id
5713
+ )
5694
5714
5695
- move_operation_response = self .operation_index (
5696
- index_name = tmp_index_name ,
5697
- operation_index_params = OperationIndexParams (
5698
- operation = OperationType .MOVE ,
5699
- destination = index_name ,
5700
- ),
5701
- request_options = request_options ,
5702
- )
5703
- self .wait_for_task (
5704
- index_name = tmp_index_name , task_id = move_operation_response .task_id
5705
- )
5715
+ return ReplaceAllObjectsResponse (
5716
+ copy_operation_response = copy_operation_response ,
5717
+ batch_responses = batch_responses ,
5718
+ move_operation_response = move_operation_response ,
5719
+ )
5720
+ except Exception as e :
5721
+ self .delete_index (tmp_index_name )
5706
5722
5707
- return ReplaceAllObjectsResponse (
5708
- copy_operation_response = copy_operation_response ,
5709
- batch_responses = batch_responses ,
5710
- move_operation_response = move_operation_response ,
5711
- )
5723
+ raise e
5712
5724
5713
5725
def index_exists (self , index_name : str ) -> bool :
5714
5726
"""
0 commit comments