Skip to content

fix: skip alerts with unknown Status instead of crashing#2235

Open
Darkandz wants to merge 2 commits into
elementary-data:masterfrom
Darkandz:fix/alert-filter-unknown-status
Open

fix: skip alerts with unknown Status instead of crashing#2235
Darkandz wants to merge 2 commits into
elementary-data:masterfrom
Darkandz:fix/alert-filter-unknown-status

Conversation

@Darkandz
Copy link
Copy Markdown

@Darkandz Darkandz commented May 16, 2026

Summary

apply_filters_schema_on_alert constructs Status(alert.data.status) unconditionally at elementary/monitor/api/alerts/alert_filters.py:53. When a row in get_pending_alerts carries status='none' (e.g., a model that was selected but not actually executed in the dbt run), the whole edr monitor invocation crashes with ValueError: 'none' is not a valid Status. One bad row poisons the entire alert batch — no alert is delivered.

Fix

Wrap the Status(...) call in _safe_parse_status. On unknown values it logs a warning and the alert is filtered out (returns False). This matches the behavior the alert would have had anyway under the default status filter (FAIL/ERROR/RUNTIME_ERROR/WARN) had 'none' been a recognized value — except now the rest of the batch is unaffected.

Reproduction

A real get_pending_alerts row from a ClickHouse-backed warehouse with status='none' (and model_unique_id, materialization, full_refresh all null) triggers the original stack trace at alert_filters.py:53Status('none'). After the fix the row is dropped with a logged warning; other alerts in the same batch are sent normally.

Test plan

  • Added test_filter_alerts_skips_unknown_status covering both the default status filter and an empty status filter.
  • `pytest tests/unit/monitor/api/alerts/test_alert_filters.py` — 9 passed.
  • `pre-commit` hooks (black, isort, flake8, mypy) clean on the changed files.

Summary by CodeRabbit

  • Bug Fixes

    • Alerts with unrecognized or missing status values are now gracefully skipped during filtering instead of causing errors, improving stability.
  • Tests

    • Added unit tests to ensure invalid alert statuses are dropped and valid alerts continue to be processed.

Review Change Stack

@github-actions
Copy link
Copy Markdown
Contributor

👋 @Darkandz
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in this pull request.

@Darkandz Darkandz requested a deployment to elementary_test_env May 16, 2026 12:44 — with GitHub Actions Waiting
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 791a6030-d6e3-477f-a479-38525dfa7696

📥 Commits

Reviewing files that changed from the base of the PR and between 99f528b and aec0264.

📒 Files selected for processing (1)
  • elementary/monitor/api/alerts/alert_filters.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • elementary/monitor/api/alerts/alert_filters.py

📝 Walkthrough

Walkthrough

This PR adds resilient status parsing for alert filtering. A new _safe_parse_status helper converts raw status strings to the Status enum, logging warnings and returning None for unrecognized values. The alert filter now skips alerts with unparseable statuses instead of raising exceptions. Test coverage verifies the graceful handling of invalid statuses.

Changes

Safe alert status parsing

Layer / File(s) Summary
Safe status parsing and integration
elementary/monitor/api/alerts/alert_filters.py
New _safe_parse_status helper converts raw status strings to Status enum, returning None and logging a warning for unrecognized values. apply_filters_schema_on_alert integrates the helper and skips alerts with unparseable statuses instead of raising ValueError.
Test coverage for unknown status handling
tests/unit/monitor/api/alerts/test_alert_filters.py
Added _alert_with_status helper to construct test alerts with specific statuses, and test_filter_alerts_skips_unknown_status verifies that filter_alerts silently skips alerts with unrecognized statuses while retaining valid ones across different filter configurations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble on bad statuses with care,
A gentle warning drifts through the air.
When a value is strange,
I hop round that range,
And skip it with grace—no crash, all fair! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: skip alerts with unknown Status instead of crashing' directly and clearly summarizes the main change: handling unknown alert statuses by skipping them rather than raising an exception.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Darkandz Darkandz requested a deployment to elementary_test_env May 16, 2026 12:50 — with GitHub Actions Waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant