@@ -620,57 +620,63 @@ async def replace_all_objects(
620620 """
621621 tmp_index_name = self .create_temporary_name (index_name )
622622
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 ,
635647 request_options = request_options ,
636648 )
637649
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+ )
647653
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+ )
651658
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+ )
656670
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 )
668678
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
674680
675681 async def index_exists (self , index_name : str ) -> bool :
676682 """
@@ -5658,57 +5664,63 @@ def replace_all_objects(
56585664 """
56595665 tmp_index_name = self .create_temporary_name (index_name )
56605666
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 ,
56735691 request_options = request_options ,
56745692 )
56755693
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+ )
56855697
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+ )
56895702
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+ )
56945714
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 )
57065722
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
57125724
57135725 def index_exists (self , index_name : str ) -> bool :
57145726 """
0 commit comments