2121from lib .core .serviceproviders import SuerannotateServiceProvider
2222from lib .core .usecases .base import BaseReportableUseCae
2323from lib .core .usecases .base import BaseUseCase
24+ from requests .exceptions import RequestException
2425
2526logger = logging .getLogger ("root" )
2627
@@ -418,7 +419,9 @@ def validate_project_name(self):
418419 def get_annotation_classes_repo (self , project : ProjectEntity ):
419420 return self ._annotation_classes_repo (self ._backend_service , project )
420421
421- def _copy_annotation_classes (self , annotation_classes_entity_mapping : dict , project : ProjectEntity ):
422+ def _copy_annotation_classes (
423+ self , annotation_classes_entity_mapping : dict , project : ProjectEntity
424+ ):
422425 annotation_classes = self .annotation_classes .get_all ()
423426 for annotation_class in annotation_classes :
424427 annotation_class_copy = copy .copy (annotation_class )
@@ -448,42 +451,49 @@ def _copy_settings(self, to_project: ProjectEntity):
448451 setting_copy .project_id = to_project .uuid
449452 new_settings .update (setting_copy )
450453
451- def _copy_workflow (self , annotation_classes_entity_mapping : dict , to_project : ProjectEntity ):
454+ def _copy_workflow (
455+ self , annotation_classes_entity_mapping : dict , to_project : ProjectEntity
456+ ):
452457 new_workflows = self ._workflows_repo (self ._backend_service , to_project )
453458 for workflow in self .workflows .get_all ():
454- existing_workflow_ids = list (
455- map (lambda i : i .uuid , new_workflows .get_all ())
456- )
459+ existing_workflow_ids = list (map (lambda i : i .uuid , new_workflows .get_all ()))
457460 workflow_data = copy .copy (workflow )
458461 workflow_data .project_id = to_project .uuid
459- workflow_data .class_id = annotation_classes_entity_mapping [workflow .class_id ].uuid
462+ workflow_data .class_id = annotation_classes_entity_mapping [
463+ workflow .class_id
464+ ].uuid
460465 new_workflows .insert (workflow_data )
461466 workflows = new_workflows .get_all ()
462- new_workflow = next ((
463- work_flow
464- for work_flow in workflows
465- if work_flow .uuid not in existing_workflow_ids
466- ), None )
467+ new_workflow = next (
468+ (
469+ work_flow
470+ for work_flow in workflows
471+ if work_flow .uuid not in existing_workflow_ids
472+ ),
473+ None ,
474+ )
467475 workflow_attributes = []
468476 for attribute in workflow_data .attribute :
469477 for annotation_attribute in annotation_classes_entity_mapping [
470478 workflow .class_id
471479 ].attribute_groups :
472480 if (
473- attribute ["attribute" ]["attribute_group" ]["name" ]
474- == annotation_attribute ["name" ]
481+ attribute ["attribute" ]["attribute_group" ]["name" ]
482+ == annotation_attribute ["name" ]
475483 ):
476484 for annotation_attribute_value in annotation_attribute [
477485 "attributes"
478486 ]:
479487 if (
480- annotation_attribute_value ["name" ]
481- == attribute ["attribute" ]["name" ]
488+ annotation_attribute_value ["name" ]
489+ == attribute ["attribute" ]["name" ]
482490 ):
483491 workflow_attributes .append (
484492 {
485493 "workflow_id" : new_workflow .uuid ,
486- "attribute_id" : annotation_attribute_value ["id" ]
494+ "attribute_id" : annotation_attribute_value [
495+ "id"
496+ ],
487497 }
488498 )
489499 break
@@ -508,27 +518,32 @@ def execute(self):
508518 f"Cloning annotation classes from { self ._project .name } to { self ._project_to_create .name } ."
509519 )
510520 try :
511- self ._copy_annotation_classes (annotation_classes_entity_mapping , project )
521+ self ._copy_annotation_classes (
522+ annotation_classes_entity_mapping , project
523+ )
512524 annotation_classes_created = True
513- except AppException :
525+ except ( AppException , RequestException ) as e :
514526 self .reporter .log_warning (
515527 f"Failed to clone annotation classes from { self ._project .name } to { self ._project_to_create .name } ."
516528 )
529+ self .reporter .log_debug (str (e ), exc_info = True )
530+
517531 if self ._include_settings :
518532 self .reporter .log_info (
519533 f"Cloning settings from { self ._project .name } to { self ._project_to_create .name } ."
520534 )
521535 try :
522536 self ._copy_settings (project )
523- except AppException :
537+ except ( AppException , RequestException ) as e :
524538 self .reporter .log_warning (
525539 f"Failed to clone settings from { self ._project .name } to { self ._project_to_create .name } ."
526540 )
541+ self .reporter .log_debug (str (e ), exc_info = True )
527542
528543 if self ._include_workflow and self ._include_annotation_classes :
529544 if self ._project .project_type in (
530- constances .ProjectType .DOCUMENT .value ,
531- constances .ProjectType .VIDEO .value
545+ constances .ProjectType .DOCUMENT .value ,
546+ constances .ProjectType .VIDEO .value ,
532547 ):
533548 self .reporter .log_warning (
534549 "Workflow copy is deprecated for "
@@ -544,20 +559,22 @@ def execute(self):
544559 )
545560 try :
546561 self ._copy_workflow (annotation_classes_entity_mapping , project )
547- except AppException :
562+ except ( AppException , RequestException ) as e :
548563 self .reporter .log_warning (
549564 f"Failed to workflow from { self ._project .name } to { self ._project_to_create .name } ."
550565 )
566+ self .reporter .log_debug (str (e ), exc_info = True )
551567 if self ._include_contributors :
552568 self .reporter .log_info (
553569 f"Cloning contributors from { self ._project .name } to { self ._project_to_create .name } ."
554570 )
555571 try :
556572 self ._copy_include_contributors (project )
557- except AppException :
573+ except ( AppException , RequestException ) as e :
558574 self .reporter .log_warning (
559575 f"Failed to clone contributors from { self ._project .name } to { self ._project_to_create .name } ."
560576 )
577+ self .reporter .log_debug (str (e ), exc_info = True )
561578 self ._response .data = self ._projects .get_one (
562579 uuid = project .uuid , team_id = project .team_id
563580 )
@@ -709,10 +726,12 @@ def validate_image_quality(self):
709726 def validate_project_type (self ):
710727 project = self ._projects .get_one (uuid = self ._project_id , team_id = self ._team_id )
711728 for attribute in self ._to_update :
712- if (
713- attribute .get ("attribute" , "" ) == "ImageQuality"
714- and project .project_type in [constances .ProjectType .VIDEO .value , constances .ProjectType .DOCUMENT .value ]
715- ):
729+ if attribute .get (
730+ "attribute" , ""
731+ ) == "ImageQuality" and project .project_type in [
732+ constances .ProjectType .VIDEO .value ,
733+ constances .ProjectType .DOCUMENT .value ,
734+ ]:
716735 raise AppValidationException (
717736 constances .DEPRICATED_DOCUMENT_VIDEO_MESSAGE
718737 )
0 commit comments