mirror of
https://github.com/clearml/clearml-server
synced 2025-03-03 18:54:20 +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):
|
class ProjectTaskParentsRequest(MultiProjectRequest):
|
||||||
tasks_state = ActualEnumField(EntityVisibility)
|
tasks_state = ActualEnumField(EntityVisibility)
|
||||||
|
task_name = fields.StringField()
|
||||||
|
|
||||||
|
|
||||||
class ProjectHyperparamValuesRequest(MultiProjectRequest):
|
class ProjectHyperparamValuesRequest(MultiProjectRequest):
|
||||||
|
@ -977,6 +977,7 @@ class ProjectBLL:
|
|||||||
projects: Sequence[str],
|
projects: Sequence[str],
|
||||||
include_subprojects: bool,
|
include_subprojects: bool,
|
||||||
state: Optional[EntityVisibility] = None,
|
state: Optional[EntityVisibility] = None,
|
||||||
|
name: str = None,
|
||||||
) -> Sequence[dict]:
|
) -> Sequence[dict]:
|
||||||
"""
|
"""
|
||||||
Get list of unique parent tasks sorted by task name for the passed company projects
|
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(
|
parents = Task.get_many_with_join(
|
||||||
company_id,
|
company_id,
|
||||||
query=Q(id__in=parent_ids),
|
query=Q(id__in=parent_ids),
|
||||||
|
query_dict={"name": name} if name else None,
|
||||||
allow_public=True,
|
allow_public=True,
|
||||||
override_projection=("id", "name", "project.name"),
|
override_projection=("id", "name", "project.name"),
|
||||||
)
|
)
|
||||||
|
|
||||||
return sorted(parents, key=itemgetter("name"))
|
return sorted(parents, key=itemgetter("name"))
|
||||||
|
|
||||||
@classmethod
|
@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,
|
projects=request.projects,
|
||||||
include_subprojects=request.include_subprojects,
|
include_subprojects=request.include_subprojects,
|
||||||
state=request.tasks_state,
|
state=request.tasks_state,
|
||||||
|
name=request.task_name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,33 @@ class TestTaskParent(TestService):
|
|||||||
parents,
|
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):
|
def test_query_by_state(self):
|
||||||
project_name = "Test parents project"
|
project_name = "Test parents project"
|
||||||
project = self.create_temp("projects", name=project_name, description="test")
|
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])
|
self.assertEqual([parent1, parent2], [p.id for p in parents])
|
||||||
|
|
||||||
# Active tasks
|
# 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])
|
self.assertEqual([parent1], [p.id for p in parents])
|
||||||
|
|
||||||
# Archived tasks
|
# 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])
|
self.assertEqual([parent2], [p.id for p in parents])
|
||||||
|
|
||||||
def new_task(self, **kwargs):
|
def new_task(self, **kwargs):
|
||||||
self.update_missing(
|
self.update_missing(kwargs, type="testing", name="test task parents")
|
||||||
kwargs, type="testing", name="test task parents"
|
|
||||||
)
|
|
||||||
return self.create_temp("tasks", **kwargs)
|
return self.create_temp("tasks", **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user