-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: FIT-1078: set task state correctly on import #8983
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
Merged
+811
−102
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
56e46bc
fix: FIT-1078: set task state correctly on import
matt-bernstein 6a12d78
remove unused arg
matt-bernstein 94c2274
move storage fsm tests to lso
matt-bernstein da63d6d
fix import
matt-bernstein 7d61b03
Apply pre-commit linters
matt-bernstein 3ef6101
import
matt-bernstein 1a15c70
tests fail properly
matt-bernstein 94bfb95
Apply pre-commit linters
matt-bernstein 402dc87
Merge branch 'develop' into 'fb-FIT-1078-2/task-import-state'
matt-bernstein dcb548c
stub state inference in LSO
matt-bernstein 6997555
fix test
matt-bernstein 446d295
Merge branch 'develop' into 'fb-FIT-1078-2/task-import-state'
matt-bernstein ba8ccfd
Apply pre-commit linters
matt-bernstein f0a5596
use new backfill for storages
matt-bernstein 6e1d64a
Merge remote-tracking branch 'origin/develop' into fb-FIT-1078-2/task…
matt-bernstein 727fe8a
fix settings switch
matt-bernstein 098ce9b
remove entity_type arg
matt-bernstein 204580b
swap out inference func
matt-bernstein 4dc9dd5
remove unused util
matt-bernstein fe3f76a
remove unused arguments
matt-bernstein 0fd8b5b
rename lso function to match lse
matt-bernstein 3cb5cd4
Merge remote-tracking branch 'origin/develop' into fb-FIT-1078-2/task…
matt-bernstein 2c8e177
remove unused tests
matt-bernstein 3dc4e47
Revert "remove unused tests"
matt-bernstein 6c39f8a
re-add util
matt-bernstein 4558abc
replace backfill function
matt-bernstein 2f37133
Merge remote-tracking branch 'origin/develop' into fb-FIT-1078-2/task…
matt-bernstein 1ba391d
use same FSM init for bulk import as for import storage
matt-bernstein ac7d2bb
add comment
matt-bernstein 9de300f
add test
matt-bernstein ba684fa
skip
matt-bernstein e9966e0
Merge remote-tracking branch 'origin/develop' into fb-FIT-1078-2/task…
matt-bernstein 8c59d0d
Merge branch 'develop' into 'fb-FIT-1078-2/task-import-state'
matt-bernstein 83ae652
Merge branch 'develop' into 'fb-FIT-1078-2/task-import-state'
matt-bernstein a338e75
Merge branch 'develop' into 'fb-FIT-1078-2/task-import-state'
matt-bernstein 5cb78a1
add back get_or_initialize params
matt-bernstein f4b48b3
move function from utils to state_inference
matt-bernstein 29fc195
helpers note
matt-bernstein 8308355
Merge remote-tracking branch 'origin/develop' into fb-FIT-1078-2/task…
matt-bernstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import logging | ||
| from typing import Optional | ||
|
|
||
| from core.utils.common import load_func | ||
| from django.conf import settings | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _get_or_infer_state(entity) -> Optional[str]: | ||
| """ | ||
| Infer what the FSM state should be based on entity's current data. | ||
|
|
||
| This is used for "cold start" scenarios where entities exist in the database | ||
| but don't have FSM state records yet (e.g., after FSM deployment to production | ||
| with pre-existing data). | ||
|
|
||
| Args: | ||
| entity: The entity to infer state for (Task, Project, or Annotation) | ||
|
|
||
| Returns: | ||
| Inferred state value, or None if entity type not supported | ||
|
|
||
| Examples: | ||
| >>> task = Task.objects.get(id=123) | ||
| >>> task.is_labeled = True | ||
| >>> _get_or_infer_state(task) | ||
| 'COMPLETED' | ||
|
|
||
| >>> project = Project.objects.get(id=456) | ||
| >>> _get_or_infer_state(project) | ||
| 'CREATED' | ||
| """ | ||
| from fsm.state_choices import AnnotationStateChoices, ProjectStateChoices, TaskStateChoices | ||
|
|
||
| entity_type = entity._meta.model_name.lower() | ||
|
|
||
| if entity_type == 'task': | ||
| # Task state depends on whether it has been labeled | ||
| return TaskStateChoices.COMPLETED if entity.is_labeled else TaskStateChoices.CREATED | ||
| elif entity_type == 'project': | ||
| # Project state depends on task completion | ||
| # If no tasks exist, project is CREATED | ||
| # If any tasks are completed, project is at least IN_PROGRESS | ||
| # If all tasks are completed, project is COMPLETED | ||
| tasks = entity.tasks.all() | ||
| if not tasks.exists(): | ||
| return ProjectStateChoices.CREATED | ||
|
|
||
| # Count labeled tasks to determine project state | ||
| total_tasks = tasks.count() | ||
| labeled_tasks = tasks.filter(is_labeled=True).count() | ||
|
|
||
| if labeled_tasks == 0: | ||
| return ProjectStateChoices.CREATED | ||
| elif labeled_tasks == total_tasks: | ||
| return ProjectStateChoices.COMPLETED | ||
| else: | ||
| return ProjectStateChoices.IN_PROGRESS | ||
| elif entity_type == 'annotation': | ||
| # Annotations are SUBMITTED when created | ||
| return AnnotationStateChoices.SUBMITTED | ||
| else: | ||
| logger.warning( | ||
| f'Cannot infer state for unknown entity type: {entity_type}', | ||
| extra={ | ||
| 'event': 'fsm.infer_state_unknown_type', | ||
| 'entity_type': entity_type, | ||
| 'entity_id': entity.pk, | ||
| }, | ||
| ) | ||
| return None | ||
|
|
||
|
|
||
| def get_or_infer_state(entity) -> Optional[str]: | ||
| func = load_func(settings.FSM_INFERENCE_FUNCTION) | ||
| return func(entity) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.