2020import  structlog   # type: ignore 
2121
2222from  .diff  import  Diff , DiffElement 
23- from  .enum  import  DiffSyncModelFlags , DiffSyncFlags , DiffSyncStatus 
23+ from  .enum  import  DiffSyncModelFlags , DiffSyncFlags , DiffSyncStatus ,  DiffSyncActions 
2424from  .exceptions  import  ObjectNotFound , ObjectNotCreated , ObjectNotUpdated , ObjectNotDeleted , ObjectCrudException 
2525from  .utils  import  intersection , symmetric_difference 
2626
@@ -296,7 +296,7 @@ def __init__(  # pylint: disable=too-many-arguments
296296        # Local state maintained during synchronization 
297297        self .logger : structlog .BoundLogger  =  self .base_logger 
298298        self .model_class : Type ["DiffSyncModel" ]
299-         self .action : Optional [str ] =  None 
299+         self .action : Optional [DiffSyncActions ] =  None 
300300
301301    def  incr_elements_processed (self , delta : int  =  1 ):
302302        """Increment self.elements_processed, then call self.callback if present.""" 
@@ -353,11 +353,11 @@ def sync_diff_element(self, element: DiffElement, parent_model: "DiffSyncModel"
353353            self .logger .warning ("No object resulted from sync, will not process child objects." )
354354            return  changed 
355355
356-         if  self .action  ==  "create" :
356+         if  self .action  ==  DiffSyncActions . CREATE :
357357            if  parent_model :
358358                parent_model .add_child (model )
359359            self .dst_diffsync .add (model )
360-         elif  self .action  ==  "delete" :
360+         elif  self .action  ==  DiffSyncActions . DELETE :
361361            if  parent_model :
362362                parent_model .remove_child (model )
363363            if  model .model_flags  &  DiffSyncModelFlags .SKIP_CHILDREN_ON_DELETE :
@@ -390,16 +390,16 @@ def sync_model(
390390            return  (False , model )
391391
392392        try :
393-             self .logger .debug (f"Attempting model { self .action }  )
394-             if  self .action  ==  "create" :
393+             self .logger .debug (f"Attempting model { self .action . value }  )
394+             if  self .action  ==  DiffSyncActions . CREATE :
395395                if  model  is  not None :
396396                    raise  ObjectNotCreated (f"Failed to create { self .model_class .get_type ()} { ids }  )
397397                model  =  self .model_class .create (diffsync = self .dst_diffsync , ids = ids , attrs = attrs )
398-             elif  self .action  ==  "update" :
398+             elif  self .action  ==  DiffSyncActions . UPDATE :
399399                if  model  is  None :
400400                    raise  ObjectNotUpdated (f"Failed to update { self .model_class .get_type ()} { ids }  )
401401                model  =  model .update (attrs = attrs )
402-             elif  self .action  ==  "delete" :
402+             elif  self .action  ==  DiffSyncActions . DELETE :
403403                if  model  is  None :
404404                    raise  ObjectNotDeleted (f"Failed to delete { self .model_class .get_type ()} { ids }  )
405405                model  =  model .delete ()
@@ -410,7 +410,7 @@ def sync_model(
410410                status , message  =  model .get_status ()
411411            else :
412412                status  =  DiffSyncStatus .FAILURE 
413-                 message  =  f"{ self .model_class .get_type ()} { self .action }  
413+                 message  =  f"{ self .model_class .get_type ()} { self .action . value }  
414414
415415        except  ObjectCrudException  as  exception :
416416            status  =  DiffSyncStatus .ERROR 
@@ -424,7 +424,7 @@ def sync_model(
424424
425425        return  (True , model )
426426
427-     def  log_sync_status (self , action : Optional [str ], status : DiffSyncStatus , message : str ):
427+     def  log_sync_status (self , action : Optional [DiffSyncActions ], status : DiffSyncStatus , message : str ):
428428        """Log the current sync status at the appropriate verbosity with appropriate context. 
429429
430430        Helper method to `sync_diff_element`/`sync_model`. 
0 commit comments