Skip to content

fix: honor model disable_on_cluster when rebuilding catalog relations (#749) - #820

Open
meat-daemon-404 wants to merge 1 commit into
ClickHouse:mainfrom
meat-daemon-404:fix/disable-on-cluster-rebuild-749
Open

meat-daemon-404 wants to merge 1 commit into
ClickHouse:mainfrom
meat-daemon-404:fix/disable-on-cluster-rebuild-749

Conversation

@meat-daemon-404

@meat-daemon-404 meat-daemon-404 commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

Fixes #749.

  • Updated on_cluster_clause in dbt/include/clickhouse/macros/materializations/table.sql so that inside a node context (this is defined) for object-level DDL (relation is not none and relation.identifier), adapter.should_on_cluster(relation=scope) evaluates this instead of a catalog-loaded existing_relation.
  • Preserves existing behavior for schema-level DDL (relation.identifier is None, such as create_schema/drop_schema) and outside a node context (run-operation, run-level hooks).
  • Added unit tests in tests/unit/test_on_cluster_clause.py covering disable_on_cluster=true rebuilds, normal cluster models with SYNC, schema DDL inside a node context, and calls outside a node context.

Checklist

  • Unit tests covering the common scenarios were added (tests/unit/test_on_cluster_clause.py; verified macro rendering directly with Jinja2 and linted with ruff check; full pytest suite requires dbt-core / ClickHouse in CI)

Note

Medium Risk
Changes distributed DDL decision logic for all table-level macro paths that use on_cluster_clause; scope is narrow but affects cluster-wide DDL behavior on rebuilds.

Overview
Fixes incorrect ON CLUSTER emission when a model is rebuilt with disable_on_cluster=true while the catalog still reports cluster-capable metadata on the existing relation.

The on_cluster_clause macro now picks a scope relation: for table-level DDL inside a model run (this is defined and relation.identifier is set), it calls adapter.should_on_cluster with this instead of the catalog existing_relation. Schema-level DDL (identifier is None) and contexts without this still use the passed-in relation unchanged.

New unit tests in test_on_cluster_clause.py exercise rebuild with cluster disabled on this, normal ON CLUSTER … SYNC output, schema DDL, and calls outside a node context.

Reviewed by Cursor Bugbot for commit 66b9f71. Bugbot is set up for automated code reviews on this repo. Configure here.

@cla-assistant

cla-assistant Bot commented Nov 23, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

disable_on_cluster=true models break on their second run (rebuild uses ON CLUSTER from the catalog relation)

3 participants