-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: FIT-710: Enable FSM state fields in serializers and models #8775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ation) This PR adds the foundational code for exposing FSM state in API responses: - FSMStateField: DRF serializer field for exposing state - FSMStateMetadataField: DRF serializer field for exposing state with metadata - FSMStateQuerySetMixin: QuerySet mixin for annotating state (prevents N+1 queries) - FSMMultiStateQuerySetMixin: Extended mixin with metadata support This is foundation code only - no implementation/usage is included in this PR.
This PR adds the enablement code for FSM state fields: - Add FSMStateField to Task, Annotation, and Data Manager serializers - Add annotate_fsm_state() usage in Task, Project, Annotation models - Add with_state() methods to model managers for convenient state annotation This enables state fields to be exposed in API responses when feature flags are enabled. Based on fb-fit-710 foundation code.
✅ Deploy Preview for label-studio-docs-new-theme canceled.
|
✅ Deploy Preview for label-studio-storybook canceled.
|
✅ Deploy Preview for heartex-docs canceled.
|
✅ Deploy Preview for label-studio-playground canceled.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #8775 +/- ##
============================================
+ Coverage 67.28% 80.67% +13.39%
============================================
Files 804 253 -551
Lines 62347 23107 -39240
Branches 10419 0 -10419
============================================
- Hits 41951 18642 -23309
+ Misses 20393 4465 -15928
+ Partials 3 0 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This pull request adds robust support for annotating and exposing finite state machine (FSM) state information for core entities (Task, Project, Annotation) in the Data Manager and API responses, while ensuring zero performance impact when FSM-related feature flags are disabled. The main improvements include new reusable mixins and serializer fields for efficient state annotation, integration of FSM state into querysets and serializers, and feature flag-based conditional exposure.
FSM State Annotation & API Exposure
FSMStateQuerySetMixininfsm/queryset_mixins.py, providing an efficientannotate_fsm_state()method for Django querysets to annotate entities with their current FSM state using optimized subqueries, avoiding N+1 queries. Annotation is strictly controlled by two feature flags for performance and rollout safety.FSMStateFieldinfsm/serializer_fields.py, a DRF serializer field that exposes the FSM state in API responses, using annotated values when available or falling back to the state manager. The field is read-only and respects feature flags for conditional exposure.Integration with Data Manager and Serializers
TaskQuerySet,ProjectQuerySet, andAnnotationQuerySetto inherit fromFSMStateQuerySetMixin, allowing FSM state annotation in their respective managers (TaskManager,ProjectManager,AnnotationManager). Added.with_state()helper methods for convenient access to annotated querysets. [1] [2] [3]statefield (usingFSMStateField) to theDataManagerTaskSerializer, and ensured its conditional removal from API output based on feature flags. [1] [2]annotate_statefunction and registered it inDATA_MANAGER_ANNOTATIONS_MAP, enabling FSM state annotation as a Data Manager column. [1] [2]Manager and QuerySet Enhancements
TaskManager,ProjectManager,AnnotationManager) to return FSM-enabled querysets and support.with_state()for annotated queries, ensuring seamless integration and consistent usage patterns. [1] [2] [3]These changes collectively provide a scalable, performant, and feature-flagged approach to FSM state management and exposure in both backend queries and API responses.
References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]