fix(metrics): correct never-tested technique query [FASE-2.6]
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Use distinct technique_id list filtering so untested techniques are returned reliably on SQLite and Postgres.
This commit is contained in:
@@ -51,13 +51,17 @@ def get_coverage_by_tactic(db: Session) -> list[dict]:
|
||||
|
||||
def get_never_tested_techniques(db: Session) -> list[dict]:
|
||||
"""Techniques that have never had a test created."""
|
||||
tested_technique_ids = db.query(Test.technique_id).distinct().subquery()
|
||||
techniques = (
|
||||
db.query(Technique)
|
||||
.filter(~Technique.id.in_(db.query(tested_technique_ids)))
|
||||
.order_by(Technique.mitre_id)
|
||||
tested_ids = [
|
||||
row[0]
|
||||
for row in db.query(Test.technique_id)
|
||||
.filter(Test.technique_id.isnot(None))
|
||||
.distinct()
|
||||
.all()
|
||||
)
|
||||
]
|
||||
query = db.query(Technique)
|
||||
if tested_ids:
|
||||
query = query.filter(~Technique.id.in_(tested_ids))
|
||||
techniques = query.order_by(Technique.mitre_id).all()
|
||||
return [
|
||||
{
|
||||
"mitre_id": t.mitre_id,
|
||||
|
||||
Reference in New Issue
Block a user