mirror of
https://github.com/clearml/clearml-server
synced 2025-03-03 02:33:02 +00:00
Support filtering by task name in projects.get_task_parent
This commit is contained in:
parent
4c22757002
commit
4291ad682a
@ -45,6 +45,7 @@ class MultiProjectRequest(models.Base):
|
||||
|
||||
class ProjectTaskParentsRequest(MultiProjectRequest):
|
||||
tasks_state = ActualEnumField(EntityVisibility)
|
||||
task_name = fields.StringField()
|
||||
|
||||
|
||||
class ProjectHyperparamValuesRequest(MultiProjectRequest):
|
||||
|
@ -977,6 +977,7 @@ class ProjectBLL:
|
||||
projects: Sequence[str],
|
||||
include_subprojects: bool,
|
||||
state: Optional[EntityVisibility] = None,
|
||||
name: str = None,
|
||||
) -> Sequence[dict]:
|
||||
"""
|
||||
Get list of unique parent tasks sorted by task name for the passed company projects
|
||||
@ -1003,9 +1004,11 @@ class ProjectBLL:
|
||||
parents = Task.get_many_with_join(
|
||||
company_id,
|
||||
query=Q(id__in=parent_ids),
|
||||
query_dict={"name": name} if name else None,
|
||||
allow_public=True,
|
||||
override_projection=("id", "name", "project.name"),
|
||||
)
|
||||
|
||||
return sorted(parents, key=itemgetter("name"))
|
||||
|
||||
@classmethod
|
||||
|
@ -1227,4 +1227,10 @@ get_task_parents {
|
||||
}
|
||||
}
|
||||
}
|
||||
"999.0": ${get_task_parents."2.13"} {
|
||||
request.properties.task_name {
|
||||
description: Task name pattern for the returned parent tasks
|
||||
type: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -509,5 +509,6 @@ def get_task_parents(
|
||||
projects=request.projects,
|
||||
include_subprojects=request.include_subprojects,
|
||||
state=request.tasks_state,
|
||||
name=request.task_name,
|
||||
)
|
||||
}
|
||||
|
@ -56,6 +56,33 @@ class TestTaskParent(TestService):
|
||||
parents,
|
||||
)
|
||||
|
||||
def test_query_by_name(self):
|
||||
project_name = "Test parents project"
|
||||
project = self.create_temp("projects", name=project_name, description="test")
|
||||
|
||||
parent_names = [f"Parent{i}" for i in range(3)]
|
||||
parents = [self.new_task(project=project, name=name) for name in parent_names]
|
||||
|
||||
for idx in range(2):
|
||||
self.new_task(project=project, name=f"Child{idx}", parent=parents[idx])
|
||||
|
||||
parents = self.api.projects.get_task_parents(
|
||||
projects=[project], task_name="Parent"
|
||||
).parents
|
||||
self.assertEqual(len(parents), 2)
|
||||
|
||||
for parent_name in parent_names[:2]:
|
||||
res = self.api.projects.get_task_parents(
|
||||
projects=[project], task_name=parent_name
|
||||
).parents
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0].name, parent_name)
|
||||
|
||||
parents = self.api.projects.get_task_parents(
|
||||
projects=[project], task_name=parent_names[2]
|
||||
).parents
|
||||
self.assertEqual(len(parents), 0)
|
||||
|
||||
def test_query_by_state(self):
|
||||
project_name = "Test parents project"
|
||||
project = self.create_temp("projects", name=project_name, description="test")
|
||||
@ -74,15 +101,17 @@ class TestTaskParent(TestService):
|
||||
self.assertEqual([parent1, parent2], [p.id for p in parents])
|
||||
|
||||
# Active tasks
|
||||
parents = self.api.projects.get_task_parents(projects=[project], tasks_state="active").parents
|
||||
parents = self.api.projects.get_task_parents(
|
||||
projects=[project], tasks_state="active"
|
||||
).parents
|
||||
self.assertEqual([parent1], [p.id for p in parents])
|
||||
|
||||
# Archived tasks
|
||||
parents = self.api.projects.get_task_parents(projects=[project], tasks_state="archived").parents
|
||||
parents = self.api.projects.get_task_parents(
|
||||
projects=[project], tasks_state="archived"
|
||||
).parents
|
||||
self.assertEqual([parent2], [p.id for p in parents])
|
||||
|
||||
def new_task(self, **kwargs):
|
||||
self.update_missing(
|
||||
kwargs, type="testing", name="test task parents"
|
||||
)
|
||||
self.update_missing(kwargs, type="testing", name="test task parents")
|
||||
return self.create_temp("tasks", **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user