Skip to content

fix: allow null materialization in ModelAlertDataSchema for ClickHouse compatibility#2180

Merged
arbiv merged 1 commit intomasterfrom
devin/1775713161-fix-nullable-materialization
Apr 9, 2026
Merged

fix: allow null materialization in ModelAlertDataSchema for ClickHouse compatibility#2180
arbiv merged 1 commit intomasterfrom
devin/1775713161-fix-nullable-materialization

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot commented Apr 9, 2026

Summary

Fixes a ValidationError (none is not an allowed value) when running edr monitor against ClickHouse, where the materialization column in alerts_v2 can be NULL.

ModelAlertDataSchema.materialization was typed as str (required, non-nullable). When ClickHouse returns null for this field, Pydantic v1 rejects it during PendingAlertSchema construction. This changes it to Optional[str] = None in both the Pydantic schema and the downstream ModelAlertModel, and handles None in the summary property string formatting.

Downstream code (slack.py, builder.py, base_integration.py) already guards against falsy materialization with truthiness checks or == "snapshot" comparisons, so no additional changes were needed there.

Review & Testing Checklist for Human

  • Parameter reorder in ModelAlertModel.__init__: materialization was moved after alert_class_id to satisfy Python's rule that default-valued params follow non-default ones. Verify no callers pass materialization positionally (grep for ModelAlertModel( — existing callers in format_alert and test utilities use keyword args, but confirm nothing was missed).
  • concise_name with null materialization: When materialization is None, concise_name will default to "model" (since None == "snapshot" is False). Confirm this is the desired fallback behavior rather than e.g. "unknown".
  • Ideally, reproduce with a ClickHouse instance that has a NULL materialization row in alerts_v2 and confirm edr monitor no longer crashes.

Notes

  • The root cause is that ClickHouse can store NULL for the materialization column when a model's materialization metadata is unavailable. Other warehouses may populate this field more reliably, which is why this hasn't surfaced outside ClickHouse.
  • Existing unit tests (26 tests across alert schemas, pending alerts, and model alert messages) all pass with these changes.

Link to Devin session: https://app.devin.ai/sessions/362d19b8c47b47dd9b895f512ffdd30f
Requested by: @arbiv


Open with Devin

Summary by CodeRabbit

  • Bug Fixes
    • Model alerts now support scenarios where materialization information is unavailable. Alert summaries are generated gracefully when this data is missing.

…e compatibility

When ClickHouse stores NULL for the materialization column in alerts_v2,
the JSON data contains "materialization": null. The Pydantic schema
rejected this with 'none is not an allowed value' because materialization
was typed as str (required, non-nullable).

This change makes materialization Optional[str] in both the schema and
the alert model, and handles None gracefully in string formatting.

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

👋 @devin-ai-integration[bot]
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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

Two files updated to make the materialization field optional in model alert definitions. The ModelAlertModel summary property was adjusted to conditionally include materialization when present.

Changes

Cohort / File(s) Summary
Making materialization optional
elementary/monitor/alerts/model_alert.py, elementary/monitor/fetchers/alerts/schema/alert_data.py
Updated materialization parameter from required str to Optional[str] = None in both the data schema and model. Adjusted ModelAlertModel.summary to conditionally include materialization text only when the value is present.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A field once rigid, now set free,
Optional it shall come to be—
When missing, the message adapts with grace,
Flexibility finds its perfect place! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: making materialization optional in ModelAlertDataSchema to support ClickHouse compatibility.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devin/1775713161-fix-nullable-materialization

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

Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 concise_name not updated to handle None materialization, unlike summary

The summary property was updated (lines 113-115) to gracefully handle materialization=None, but the concise_name property (lines 104-109) was not. When materialization is None, concise_name falls through to the else branch and returns "dbt model alert - {alias}", which may be incorrect (e.g., if the resource is a snapshot whose materialization data is missing). The same pattern also exists at elementary/monitor/alerts/alert_messages/builder.py:195 (asset_type = "snapshot" if alert.materialization == "snapshot" else "model"), which was also not updated.

(Refers to lines 104-109)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional behavior. When materialization is None, falling through to the else branch and defaulting to "model" is the correct safe fallback. The same pattern at builder.py:195 also defaults to "model" for the same reason.

A snapshot whose materialization metadata is missing would be an unusual edge case — in practice, if a snapshot is correctly configured in dbt, its materialization field would be populated as "snapshot". The scenario triggering this bug is model alerts in ClickHouse where the materialization column is NULL due to missing metadata, and defaulting those to "model" is the appropriate behavior.

The summary property was updated differently because it interpolates materialization directly into the string (which would produce "dbt failed to build None "alias""), while concise_name only checks equality against "snapshot" and never renders the raw value.

@arbiv arbiv merged commit 28daf9f into master Apr 9, 2026
25 checks passed
@arbiv arbiv deleted the devin/1775713161-fix-nullable-materialization branch April 9, 2026 10:58
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.

2 participants