Skip to content

Commit adf2f1f

Browse files
committed
fix(scoring): flush empty list of results and breakdown items
SQLAlchemy order of execution together with missing configuration was causing duplicates in score_definition_results and score_definition_results_breakdown tables. Apparently, SQLAlchemy needs a little help with the order of DELETE-INSERT statements in the same transaction.
1 parent 0e8def5 commit adf2f1f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

testgen/commands/run_refresh_score_cards_results.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import time
44

5-
from testgen.common.models import with_database_session
5+
from testgen.common.models import get_current_session, with_database_session
66
from testgen.common.models.scores import (
77
SCORE_CATEGORIES,
88
ScoreCard,
@@ -36,6 +36,7 @@ def run_refresh_score_cards_results(
3636
LOG.exception("CurrentStep: Stopping scorecards results refresh after unexpected error")
3737
return
3838

39+
db_session = get_current_session()
3940
for definition in definitions:
4041
LOG.info(
4142
"CurrentStep: Refreshing results for scorecard %s in project %s",
@@ -45,6 +46,10 @@ def run_refresh_score_cards_results(
4546

4647
try:
4748
fresh_score_card = definition.as_score_card()
49+
definition.results = []
50+
definition.breakdown = []
51+
db_session.flush([definition])
52+
4853
definition.results = _score_card_to_results(fresh_score_card)
4954
definition.breakdown = _score_definition_to_results_breakdown(definition)
5055
if add_history_entry:

0 commit comments

Comments
 (0)