fix(alerts): treat naive detected_at datetimes as UTC before timezone conversion - #2341
fix(alerts): treat naive detected_at datetimes as UTC before timezone conversion#2341zerafachris wants to merge 2 commits into
Conversation
dbt State (v1.11+) introduces a "reused" run status for models that are skipped because their state has not changed. This caused a ValueError when elementary tried to construct alert objects from those run results, since "reused" was not a member of the Status enum. Adding REUSED = "reused" lets alert objects be created normally; the default status filter (FAIL/ERROR/RUNTIME_ERROR/WARN) correctly excludes "reused" alerts from notifications, matching dbt's intent that a reused model is not an actionable event. Fixes elementary-data#2311. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… conversion Python's datetime.astimezone() interprets a naive datetime as *local wall-clock time*, not UTC. Since the alerts table stores timestamps in UTC, running edr on a host whose timezone is not UTC produced alerts where the "Time:" field showed the UTC value labeled with the local timezone name (e.g. 09:08 UTC displayed as "09:08 JST"). Fix: attach UTC tzinfo to the naive datetime before calling astimezone(), so the conversion is always relative to UTC regardless of the process timezone. Also update detected_at_utc to hold the tz-aware value for consistency. Fixes elementary-data#2304 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
👋 @zerafachris |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
ChangesAlert timestamp normalization
Reused alert status
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change consistently treats naive alert timestamps as UTC before timezone conversion, preventing incorrect displayed times. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment Warning |
Problem
Fixes #2304.
AlertModel.__init__callsdetected_at.astimezone(...)on a naivedatetimevalue. Python'sastimezone()interprets a naive datetime as the local wall-clock time, not UTC.Since the alerts table stores timestamps in UTC, running
edr monitoron a host whose timezone is not UTC produces alerts where the "Time:" field shows the UTC value labeled with the local timezone name:This misled users into thinking alerts were hours delayed.
Fix
Before calling
astimezone(), attachUTCtzinfo to any naive datetime so the conversion is always relative to UTC:detected_at_utcis also updated to hold the timezone-aware value for consistency (previously it held the raw naive input).Test
Added
tests/unit/alerts/test_alert_detected_at_timezone.pywith three cases:None→ fields stayNone,detected_at_str == "N/A"Summary by CodeRabbit
Bug Fixes
Improvements