From 43a5325e69c6a83af7c73dcce1c08aac67b3e6d1 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 2 Jun 2026 14:27:25 -0400 Subject: [PATCH] fix(alerts): persist AlertOperator by value to match the DB enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The alertoperator Postgres enum (migration 0002) was created with the operator VALUES as labels ('>', '<', …), but the model's Enum(AlertOperator) defaulted to persisting enum-member NAMES ('gt', 'lt', …) — so inserting any AlertRule against real Postgres raised 'invalid input value for enum alertoperator: "gt"'. Never caught because unit tests mock the DB and no integration test inserted a rule until task 250's. Add values_callable so the ORM round-trips the values. Co-Authored-By: Claude Opus 4.8 (1M context) --- steward/models/alerts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/steward/models/alerts.py b/steward/models/alerts.py index c69b3cf..3e86b8e 100644 --- a/steward/models/alerts.py +++ b/steward/models/alerts.py @@ -32,7 +32,13 @@ class AlertRule(Base): source_module: Mapped[str] = mapped_column(String(64), nullable=False) resource_name: Mapped[str] = mapped_column(String(255), nullable=False) metric_name: Mapped[str] = mapped_column(String(128), nullable=False) - operator: Mapped[AlertOperator] = mapped_column(Enum(AlertOperator), nullable=False) + # The DB enum (migration 0002) stores the operator VALUES (">", "<", …), so + # persist values rather than SQLAlchemy's default enum-member NAMES ("gt"…). + operator: Mapped[AlertOperator] = mapped_column( + Enum(AlertOperator, name="alertoperator", + values_callable=lambda e: [m.value for m in e]), + nullable=False, + ) threshold: Mapped[float] = mapped_column(Float, nullable=False) consecutive_failures_required: Mapped[int] = mapped_column(Integer, nullable=False, default=1) enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)