diff --git a/label_studio/tasks/serializers.py b/label_studio/tasks/serializers.py index e6c328f3aca4..241286a38619 100644 --- a/label_studio/tasks/serializers.py +++ b/label_studio/tasks/serializers.py @@ -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 @@ -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 diff --git a/web/libs/app-common/src/components/state-chips/state-registry.ts b/web/libs/app-common/src/components/state-chips/state-registry.ts index b2d622aa0f26..c4e4e37bca62 100644 --- a/web/libs/app-common/src/components/state-chips/state-registry.ts +++ b/web/libs/app-common/src/components/state-chips/state-registry.ts @@ -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",