Skip to content

Commit 319e0c3

Browse files
fix: FIT-1059: Not sure 'Created' is the right name for the annotation state, perhaps 'Initial' could make more sense, take a look at the screenshot (#8904)
Co-authored-by: yyassi-heartex <yyassi-heartex@users.noreply.github.com>
1 parent a83ac82 commit 319e0c3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

label_studio/tasks/serializers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from django.db import IntegrityError, transaction
1313
from drf_spectacular.utils import extend_schema_field
1414
from fsm.serializer_fields import FSMStateField
15+
from fsm.state_manager import get_state_manager
16+
from fsm.utils import is_fsm_enabled
1517
from label_studio_sdk.label_interface import LabelInterface
1618
from projects.models import Project
1719
from rest_flex_fields import FlexFieldsModelSerializer
@@ -689,8 +691,26 @@ def add_tasks(self, task_annotations, task_predictions, validated_tasks):
689691

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

694+
# Backfill FSM states for bulk-created tasks
695+
# bulk_create() bypasses save() so FSM transitions don't fire automatically
696+
self._backfill_fsm_states(self.db_tasks)
697+
692698
return db_tasks
693699

700+
def _backfill_fsm_states(self, tasks):
701+
"""
702+
Backfill FSM states for tasks created via bulk_create().
703+
704+
bulk_create() bypasses the model's save() method, so FSM transitions
705+
don't fire automatically. This sets initial CREATED state for newly imported tasks.
706+
"""
707+
if not tasks or not is_fsm_enabled(user=None):
708+
return
709+
710+
StateManager = get_state_manager()
711+
for task in tasks:
712+
StateManager.execute_transition(entity=task, transition_name='task_created', user=None)
713+
694714
@staticmethod
695715
def post_process_annotations(user, db_annotations, action):
696716
pass

web/libs/app-common/src/components/state-chips/state-registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export const stateRegistry = new StateRegistry();
248248
stateRegistry.registerBatch({
249249
CREATED: {
250250
type: StateType.INITIAL,
251-
label: "Created",
251+
label: "Initial",
252252
tooltips: {
253253
task: "Task has been created and is ready for annotation",
254254
annotation: "Annotation has been created",

0 commit comments

Comments
 (0)