Skip to content

Commit 28daf9f

Browse files
fix: allow null materialization in ModelAlertDataSchema for ClickHouse compatibility (#2180)
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: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Yosef Arbiv <yosef.arbiv@gmail.com>
1 parent 4b52f6b commit 28daf9f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

elementary/monitor/alerts/model_alert.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def __init__(
1818
alias: str,
1919
path: str,
2020
original_path: str,
21-
materialization: str,
2221
full_refresh: bool,
2322
alert_class_id: str,
23+
materialization: Optional[str] = None,
2424
message: Optional[str] = None,
2525
model_unique_id: Optional[str] = None,
2626
detected_at: Optional[datetime] = None,
@@ -110,7 +110,9 @@ def concise_name(self) -> str:
110110

111111
@property
112112
def summary(self) -> str:
113-
return f'dbt failed to build {self.materialization} "{self.alias}"'
113+
if self.materialization:
114+
return f'dbt failed to build {self.materialization} "{self.alias}"'
115+
return f'dbt failed to build "{self.alias}"'
114116

115117
def get_report_link(self) -> Optional[ReportLinkData]:
116118
return get_model_runs_link(self.report_url, self.model_unique_id)

elementary/monitor/fetchers/alerts/schema/alert_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class ModelAlertDataSchema(BaseAlertDataSchema):
249249
alias: str
250250
path: str
251251
original_path: str
252-
materialization: str
252+
materialization: Optional[str] = None
253253
full_refresh: bool
254254
message: Optional[str] = None
255255
resource_type: ResourceType = Field(ResourceType.MODEL, const=True) # type: ignore # noqa

0 commit comments

Comments
 (0)