Skip to content

populate_test_alerts_query returns prefixed column names on old ClickHouse versions, causing "Object of type Undefined is not JSON serializable" error #2228

@maanh96

Description

@maanh96

Describe the bug
On old ClickHouse versions (confirmed on 23.4), the populate_test_alerts_query macro in test_alerts.sql returns columns with table-qualified prefixes (e.g., failed_tests.alert_id, invocations.job_id) instead of plain column names. This causes the populate_test_alerts macro to receive Undefined when accessing fields like raw_test_alert.alert_id, ultimately crashing with Object of type Undefined is not JSON serializable.

To Reproduce
Steps to reproduce the behavior:

  1. Set up Elementary with a ClickHouse 23.4 warehouse
  2. Run edr monitor
  3. See error
Compilation Error in model alerts_v2 (models/alerts/alerts_v2.sql)
  Object of type Undefined is not JSON serializable
  > in macro populate_test_alerts (macros/alerts/population/test_alerts.sql)

Expected behavior
edr monitor runs successfully and sends alerts to the configured destination regardless of ClickHouse version.

Screenshots
N/A

Environment (please complete the following information):

  • Elementary CLI (edr) version: 0.23.4
  • Elementary dbt package version: 0.23.1
  • dbt version: 1.10.13
  • Data warehouse: ClickHouse 23.4
  • Infrastructure: Linux, dbt-clickhouse adapter 1.9.4

Additional context
PR #2095 partially fixed this by adding explicit AS aliases to columns that are ambiguous across joined tables (database_name, schema_name, tags, etc.). However, on ClickHouse 23.4, all columns from named CTEs/joins are returned with table prefixes, not just the ambiguous ones. Running the query directly in the database confirms columns like failed_tests.alert_id, failed_tests.data_issue_id, invocations.job_id, etc. are still returned with table prefixes on this version.

The fix is to add explicit AS aliases to all remaining unaliased columns in the final SELECT of populate_test_alerts_query macro.

failed_tests.alert_id as alert_id,
failed_tests.data_issue_id as data_issue_id,
failed_tests.test_execution_id as test_execution_id,
failed_tests.test_unique_id as test_unique_id,
....

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions