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]:
|
def get_never_tested_techniques(db: Session) -> list[dict]:
|
||||||
"""Techniques that have never had a test created."""
|
"""Techniques that have never had a test created."""
|
||||||
tested_technique_ids = db.query(Test.technique_id).distinct().subquery()
|
tested_ids = [
|
||||||
techniques = (
|
row[0]
|
||||||
db.query(Technique)
|
for row in db.query(Test.technique_id)
|
||||||
.filter(~Technique.id.in_(db.query(tested_technique_ids)))
|
.filter(Test.technique_id.isnot(None))
|
||||||
.order_by(Technique.mitre_id)
|
.distinct()
|
||||||
.all()
|
.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 [
|
return [
|
||||||
{
|
{
|
||||||
"mitre_id": t.mitre_id,
|
"mitre_id": t.mitre_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user