From 12c370edd4331e0c52f682c558db1cbf1d784bae Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 17 Jun 2026 00:36:35 +0200 Subject: [PATCH] Fix quality metric persistence ordering --- backend/app/services/quality_service.py | 2 ++ backend/tests/test_sprint7a_persistence_foundation.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/backend/app/services/quality_service.py b/backend/app/services/quality_service.py index cfd01444..e88e2ef2 100644 --- a/backend/app/services/quality_service.py +++ b/backend/app/services/quality_service.py @@ -39,6 +39,8 @@ class QualityService: completed_at=datetime.now(timezone.utc), ) db.add(quality_check) + if hasattr(db, "flush"): + db.flush() for key, value in (metrics or {}).items(): db.add( diff --git a/backend/tests/test_sprint7a_persistence_foundation.py b/backend/tests/test_sprint7a_persistence_foundation.py index 4b0f7b48..c1a346fb 100644 --- a/backend/tests/test_sprint7a_persistence_foundation.py +++ b/backend/tests/test_sprint7a_persistence_foundation.py @@ -21,6 +21,7 @@ class FakeSession: self.objects = objects or {} self.commits = 0 self.refreshes = [] + self.flushes = 0 def get(self, model, item_id): return self.objects.get((model, item_id)) @@ -31,6 +32,9 @@ class FakeSession: def commit(self) -> None: self.commits += 1 + def flush(self) -> None: + self.flushes += 1 + def refresh(self, item) -> None: self.refreshes.append(item) @@ -178,6 +182,7 @@ def test_quality_service_persists_quality_check_and_metrics() -> None: "false_positive_count", ] assert persisted_metrics[0].quality_check_id == quality_check.id + assert db.flushes == 1 assert db.commits == 1