fix(CORE-001D3B): validate alert history entry types
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
from dataclasses import asdict, dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -25,6 +26,22 @@ class AlertEvent:
|
||||
updated_at: str
|
||||
email_alerts_enabled: bool
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
for field_name in ("severity", "message", "updated_at"):
|
||||
value = getattr(self, field_name)
|
||||
if not isinstance(value, str):
|
||||
raise TypeError(f"{field_name} must be a string")
|
||||
for field_name in ("ltv_ratio", "warning_threshold", "critical_threshold", "spot_price"):
|
||||
value = getattr(self, field_name)
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
||||
raise TypeError(f"{field_name} must be numeric")
|
||||
numeric_value = float(value)
|
||||
if not math.isfinite(numeric_value):
|
||||
raise ValueError(f"{field_name} must be finite")
|
||||
setattr(self, field_name, numeric_value)
|
||||
if not isinstance(self.email_alerts_enabled, bool):
|
||||
raise TypeError("email_alerts_enabled must be a bool")
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
return asdict(self)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user