Skip to content

Commit 02609ee

Browse files
use CurrentContext for user in _update_tasks_states
1 parent 0ba6eb2 commit 02609ee

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

label_studio/projects/mixins.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def update_tasks_counters_and_task_states(
3434
tasks_number_changed,
3535
from_scratch=True,
3636
recalculate_stats_counts: Optional[Mapping[str, int]] = None,
37-
user=None,
3837
):
3938
"""
4039
Async start updating tasks counters and than rearrange
@@ -43,7 +42,6 @@ def update_tasks_counters_and_task_states(
4342
:param overlap_cohort_percentage_changed: If cohort_percentage param changed
4443
:param tasks_number_changed: If tasks number changed in project
4544
:param from_scratch: Skip calculated tasks
46-
:param user: User who is updating the tasks states
4745
"""
4846
# get only id from queryset to decrease data size in job
4947
task_ids = get_unique_ids_list(tasks_queryset)
@@ -55,7 +53,6 @@ def update_tasks_counters_and_task_states(
5553
tasks_number_changed,
5654
from_scratch=from_scratch,
5755
recalculate_stats_counts=recalculate_stats_counts,
58-
user=user,
5956
)
6057

6158
def update_tasks_states(

label_studio/projects/models.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, Mapping, Optional
66

77
from annoying.fields import AutoOneToOneField
8+
from core.current_request import CurrentContext
89
from core.label_config import (
910
check_control_in_config_by_regex,
1011
check_toname_in_config_by_regex,
@@ -484,14 +485,13 @@ def has_collaborator_enabled(self, user):
484485
return membership.exists() and membership.first().enabled
485486

486487
def _update_tasks_states(
487-
self, maximum_annotations_changed, overlap_cohort_percentage_changed, tasks_number_changed, user=None
488+
self, maximum_annotations_changed, overlap_cohort_percentage_changed, tasks_number_changed
488489
):
489490
"""
490491
Update tasks states after settings change
491492
:param maximum_annotations_changed: If maximum_annotations param changed
492493
:param overlap_cohort_percentage_changed: If cohort_percentage param changed
493494
:param tasks_number_changed: If tasks number changed in project
494-
:param user: User who is updating the tasks states
495495
"""
496496
logger.info(
497497
f'Starting _update_tasks_states with params: Project {str(self)} maximum_annotations '
@@ -533,6 +533,7 @@ def _update_tasks_states(
533533

534534
if tasks_number_changed:
535535
# FSM: Recalculate project state after task deletion or import
536+
user = CurrentContext.get_user()
536537
update_project_state_after_task_change(self, user=user)
537538

538539
def _batch_update_with_retry(self, queryset, batch_size=500, max_retries=3, **update_fields):
@@ -1184,22 +1185,18 @@ def _update_tasks_counters_and_task_states(
11841185
tasks_number_changed,
11851186
from_scratch=True,
11861187
recalculate_stats_counts: Optional[Mapping[str, int]] = None,
1187-
user=None,
11881188
):
11891189
"""
11901190
Update tasks counters and update tasks states (rearrange and/or is_labeled)
11911191
:param queryset: Tasks to update queryset
11921192
:param from_scratch: Skip calculated tasks
1193-
:param user: User who is updating the tasks states
11941193
:return: Count of updated tasks
11951194
"""
11961195
from tasks.functions import update_tasks_counters
11971196

11981197
queryset = make_queryset_from_iterable(queryset)
11991198
objs = update_tasks_counters(queryset, from_scratch)
1200-
self._update_tasks_states(
1201-
maximum_annotations_changed, overlap_cohort_percentage_changed, tasks_number_changed, user=user
1202-
)
1199+
self._update_tasks_states(maximum_annotations_changed, overlap_cohort_percentage_changed, tasks_number_changed)
12031200

12041201
if recalculate_all_stats and recalculate_stats_counts:
12051202
recalculate_all_stats(self.id, **recalculate_stats_counts)

0 commit comments

Comments
 (0)