Skip to content
Merged
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
20 changes: 20 additions & 0 deletions label_studio/tasks/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.db import IntegrityError, transaction
from drf_spectacular.utils import extend_schema_field
from fsm.serializer_fields import FSMStateField
from fsm.state_manager import get_state_manager
from fsm.utils import is_fsm_enabled
from label_studio_sdk.label_interface import LabelInterface
from projects.models import Project
from rest_flex_fields import FlexFieldsModelSerializer
Expand Down Expand Up @@ -689,8 +691,26 @@ def add_tasks(self, task_annotations, task_predictions, validated_tasks):

logging.info(f'Tasks serialization success, len = {len(self.db_tasks)}')

# Backfill FSM states for bulk-created tasks
# bulk_create() bypasses save() so FSM transitions don't fire automatically
self._backfill_fsm_states(self.db_tasks)

return db_tasks

def _backfill_fsm_states(self, tasks):
"""
Backfill FSM states for tasks created via bulk_create().

bulk_create() bypasses the model's save() method, so FSM transitions
don't fire automatically. This sets initial CREATED state for newly imported tasks.
"""
if not tasks or not is_fsm_enabled(user=None):
return

StateManager = get_state_manager()
for task in tasks:
StateManager.execute_transition(entity=task, transition_name='task_created', user=None)

@staticmethod
def post_process_annotations(user, db_annotations, action):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const stateRegistry = new StateRegistry();
stateRegistry.registerBatch({
CREATED: {
type: StateType.INITIAL,
label: "Created",
label: "Initial",
tooltips: {
task: "Task has been created and is ready for annotation",
annotation: "Annotation has been created",
Expand Down
Loading