Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion label_studio/fsm/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def transition_state(
state=new_state,
previous_state=current_state,
transition_name=transition_name,
triggered_by=user,
triggered_by=user if getattr(user, 'is_authenticated', False) else None,
context_data=context or {},
reason=reason,
organization_id=organization_id,
Expand Down
23 changes: 23 additions & 0 deletions label_studio/fsm/tests/test_fsm_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,26 @@ def test_same_state_transition_prevention(self, mock_flag_set):
# Verify state is still CREATED
current_state = self.StateManager.get_current_state_value(self.task)
assert current_state == 'CREATED'

@patch('fsm.state_manager.flag_set')
def test_transition_with_anonymous_user(self, mock_flag_set):
"""Test that transitioning state with AnonymousUser succeeds and sets triggered_by to None."""
from django.contrib.auth.models import AnonymousUser
from django.core.cache import cache

cache.clear()

mock_flag_set.return_value = True

anon_user = AnonymousUser()
success = self.StateManager.transition_state(
entity=self.task,
new_state='IN_PROGRESS',
user=anon_user,
transition_name='start_task_anon',
)
assert success

current_state_obj = self.StateManager.get_current_state_object(self.task)
assert current_state_obj.state == 'IN_PROGRESS'
assert current_state_obj.triggered_by is None
Loading