From 534ed030b898549cf04d2aec0bf1e7a547815179 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 2 Jun 2026 14:31:25 -0400 Subject: [PATCH] test(alerts): commit the test user before the rule's created_by FK Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/integration/test_alert_ansible_action.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/test_alert_ansible_action.py b/tests/integration/test_alert_ansible_action.py index e1d2ca2..a72f5d1 100644 --- a/tests/integration/test_alert_ansible_action.py +++ b/tests/integration/test_alert_ansible_action.py @@ -61,11 +61,13 @@ def test_firing_triggers_ansible_action(app, tmp_path): async def _go(): async with app.db_sessionmaker() as s: + # User must be committed before the rule's created_by FK can reference it. async with s.begin(): s.add(User( id=uid, username=f"u{uid[:8]}", email=f"{uid[:8]}@e.test", password_hash="x", role=UserRole.admin, is_active=True, )) + async with s.begin(): s.add(AlertRule( id=rule_id, name="cpu hot", source_module="host_agent", resource_name="srv1", metric_name="cpu_pct",