
    	]j              
           d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ  ej                  e      Zded	ed
eeef   dedef
dZy)a/  
Transition execution orchestrator for the FSM engine.

This module handles the execution of state transitions, coordinating between
the registry and transitions without importing StateManager to avoid circular dependencies.
StateManager imports from this module and provides its methods as parameters.
    N)AnyDictType)Model)get_state_model_for_entitytransition_registry)	BaseState)TransitionContextentitytransition_nametransition_datastate_manager_classreturnc                 H   | j                   j                  j                         }|xs i }t        j                  ||      }|st        d| d| d       |di |}|j                  dt        | dd            }	t        | |ddd|	      }
|j                  |
      }|du }|rd}d}d}n=t        |       }|st        d| d      |j                  |       }|r|j                  nd}t        d| |||||	d|}t        j                  dd	|| j                  ||||r|j                   ndd
       |j#                  |      }|j$                  ri ||j$                  }|r9t        j                  dd|| j                  |d       |j'                  |d       yt        |dd      }|j(                  r|j(                  n|j+                  |      }|j-                  | ||j.                  ||||      }|st        d|       |j1                  |       }|j3                  ||       |S )a8  
    Execute a registered transition using StateManager methods passed as parameters.

    This function is called by StateManager.execute_transition() to avoid circular imports.
    StateManager imports this module and passes itself as a parameter.

    Args:
        entity: The entity to transition
        transition_name: Name of the registered transition
        transition_data: Data for the transition (validated by Pydantic)
        user: User executing the transition
        state_manager_class: The StateManager class to use for state operations
        **context_kwargs: Additional context data

    Returns:
        The newly created state record

    Raises:
        ValueError: If transition is not found or state model is not registered
        TransitionValidationError: If transition validation fails
    zTransition 'z' not found for entity ''organization_idN)r   current_usercurrent_state_objectcurrent_statetarget_stater   z&No state model registered for entity 'zExecuting transitionzfsm.transition_execute)evententity_type	entity_idr   
from_stateto_stateuser_id)extraz%Executing side-effect only transitionzfsm.side_effect_transition)r   r   r   r   _force_state_recordF)r   	new_stater   usercontextreasonforce_state_recordz"Failed to create state record for  )_meta
model_namelowerr   get_transition
ValueErrorpopgetattrr
   get_target_stater   get_current_statestateloggerinfopkidprepare_and_validatecontext_datapost_transition_hookr"   
get_reasontransition_stater   get_current_state_objectfinalize)r   r   r   r    r   context_kwargsentity_nametransition_class
transitionr   minimal_contextr   is_side_effect_onlystate_modelr   r   r!   transition_context_datar#   r"   successstate_records                         N/root/env/lib/python3.12/site-packages/label_studio/fsm/transition_executor.py%execute_transition_with_state_managerrE      s   : ,,))//1K%+O +99+W<'88PQ\P]]^_`` "4O4J %(():GFL]_c<deO (!'O ..?L&$.# 18Ek]RSTUU  +<<VD6J,22PT   1#!' G KK-&.'$"&twwD
   )==gF "U%<"U@T@T"U 35*#YY#2	 	 	
 	''6 !-BEJ  '~~W^^:3H3H3QF!22"22'- 3 G =o=NOPP '??GL .    )__doc__loggingtypingr   r   r   django.db.modelsr   fsm.registryr   r   fsm.state_modelsr	   fsm.transitionsr
   	getLogger__name__r/   strrE   r$   rF   rD   <module>rQ      st     " " " H & -			8	$QQQ #s(^Q
 Q QrF   