Skip to content

fix: warn when catchup and repopulate_from_mvs_on_full_refresh are both set - #796

Open
m-tahoon1612 wants to merge 2 commits into
ClickHouse:mainfrom
m-tahoon1612:fix/warn-catchup-repopulate
Open

m-tahoon1612 wants to merge 2 commits into
ClickHouse:mainfrom
m-tahoon1612:fix/warn-catchup-repopulate

Conversation

@m-tahoon1612

@m-tahoon1612 m-tahoon1612 commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

A materialized view that writes into an explicit target table (materialization_target_table(ref(...))) backfills that table when it is created or fully refreshed if catchup=True, which is the default. The target table can also be configured with repopulate_from_mvs_on_full_refresh=True, which rebuilds it on a full refresh by running the SQL of every MV that points to it. With both enabled, a dbt run --full-refresh loads the same rows twice. The docs already say not to combine them, but nothing tells the user when they do.

This PR adds that check to the MV materialization in explicit target mode. When the view has catchup enabled, it looks the target table up in the dbt graph and, if that model sets repopulate_from_mvs_on_full_refresh=True, logs a warning naming both models and the two ways to fix it.

It is a warning rather than an error on purpose. Because catchup defaults to True, a project that only set repopulate_from_mvs_on_full_refresh=True on the target table already has both enabled, and failing the run would break it on upgrade.

Fixes #616

Testing:

  • New TestCatchupAndRepopulateWarning in test_table_repopulate_from_mvs_on_full_refresh.py: both settings on logs the warning on a regular run and on --full-refresh; only catchup on, and only repopulate_from_mvs_on_full_refresh on with catchup=False, log no warning. The first case fails without the macro change.
  • Against a single-node ClickHouse 26.10.3.7: tests/integration/adapter/materialized_view 55 passed (parallel and sequential), tests/integration/adapter/basic 26 passed, 1 skipped (needs a cluster), unit tests 101 passed.
  • make lint checks pass.

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A changelog entry was added following Updating the Changelog (user-facing, concise, PR link)
  • For significant changes, documentation in docs was updated with further explanations or tutorials

Note

Low Risk
Non-breaking advisory warning during MV runs; no change to refresh behavior or data paths beyond new logging.

Overview
Adds a runtime warning in explicit-target materialized view mode when catchup=True (the default) writes to a table model that also has repopulate_from_mvs_on_full_refresh=True, since a full refresh can backfill the same target twice and duplicate data.

The MV materialization calls a new clickhouse__warn_if_target_repopulates_from_mvs macro (warning only, not a compile error) that resolves the target from the dbt graph and points users to disable one of the two settings. Docs note that dbt-clickhouse logs this warning, and integration tests assert the warning appears only when both flags are on.

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

…th set

A materialized view with catchup enabled that writes into a dbt table model with repopulate_from_mvs_on_full_refresh=True backfills the target twice on a full refresh. Log a warning when both are set.

Fixes ClickHouse#616
@cla-assistant

cla-assistant Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Flipmonster Flipmonster reopened this Nov 26, 2026
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.

Raise an exception/warning when repopulate_from_mvs_on_full_refresh and catchup are set

2 participants