Fix projects aggregation on tasks with invalid status

This commit is contained in:
allegroai 2020-02-04 18:21:04 +02:00
parent b7b94e7ae5
commit eb0865662c

View File

@ -61,7 +61,7 @@ def get_by_id(call):
def make_projects_get_all_pipelines(project_ids, specific_state=None): def make_projects_get_all_pipelines(project_ids, specific_state=None):
archived = EntityVisibility.archived.value archived = EntityVisibility.archived.value
def ensure_system_tags(): def ensure_valid_fields():
""" """
Make sure system tags is always an array (required by subsequent $in in archived_tasks_cond Make sure system tags is always an array (required by subsequent $in in archived_tasks_cond
""" """
@ -73,6 +73,9 @@ def make_projects_get_all_pipelines(project_ids, specific_state=None):
"then": [], "then": [],
"else": "$system_tags", "else": "$system_tags",
} }
},
"status": {
"$ifNull": ["$status", "unknown"]
} }
} }
} }
@ -80,7 +83,7 @@ def make_projects_get_all_pipelines(project_ids, specific_state=None):
status_count_pipeline = [ status_count_pipeline = [
# count tasks per project per status # count tasks per project per status
{"$match": {"project": {"$in": project_ids}}}, {"$match": {"project": {"$in": project_ids}}},
ensure_system_tags(), ensure_valid_fields(),
{ {
"$group": { "$group": {
"_id": { "_id": {
@ -153,7 +156,7 @@ def make_projects_get_all_pipelines(project_ids, specific_state=None):
"project": {"$in": project_ids}, "project": {"$in": project_ids},
} }
}, },
ensure_system_tags(), ensure_valid_fields(),
{ {
# for each project # for each project
"$group": group_step "$group": group_step