Skip to content

fix(clickhouse): re-raise non-NOT_IMPLEMENTED errors from EXCHANGE TABLES - #6105

Open
wolfgang-aura wants to merge 3 commits into
SQLMesh:mainfrom
wolfgang-aura:fix/clickhouse-exchange-tables-reraise
Open

wolfgang-aura wants to merge 3 commits into
SQLMesh:mainfrom
wolfgang-aura:fix/clickhouse-exchange-tables-reraise

Conversation

@wolfgang-aura

@wolfgang-aura wolfgang-aura commented Sep 29, 2026 •

Copy link
Copy Markdown

Description

Fixes #6087.

ClickhouseEngineAdapter._exchange_tables caught every DatabaseError from EXCHANGE TABLES and only acted on NOT_IMPLEMENTED. Any other error, such as ACCESS_DENIED, was dropped. _insert_overwrite_by_condition then dropped the temp table in its finally and reported success while the target kept its old data.

The except block now re-raises unless the error contains NOT_IMPLEMENTED, as proposed in the issue. The non-atomic rename fallback moves out one indent level; its statements are the same, and test_exchange_tables covers that path.

Test Plan

In tests/core/engine_adapter/test_clickhouse.py:

  • test_insert_overwrite_by_condition_replace_exchange_error_propagates: on the non-partitioned replace path, EXCHANGE TABLES raises ACCESS_DENIED. The test asserts the error leaves _insert_overwrite_by_condition, and that the only DROP in the whole trace is the temporary table, dropped by the finally.
  • test_exchange_tables (the NOT_IMPLEMENTED fallback) is not edited and passes in the same run.

The test fails on unpatched main and passes with the fix. The file passes locally (35 passed). ruff check and ruff format --check pass on it. make style and make fast-test were not run.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Written with Claude (claude-sonnet-5-5) and reviewed by a second Claude instance under the Mailman harness.

…BLES

_exchange_tables caught every DatabaseError and acted only on
NOT_IMPLEMENTED, so any other failure was dropped and a FULL model
reported success over stale data.

Fixes SQLMesh#6087

Signed-off-by: wolfgang-aura <169568318+wolfgang-aura@users.noreply.github.com>
@mday-io
mday-io self-requested a review October 2, 2026 02:42
@mday-io mday-io self-assigned this Oct 2, 2026

@mday-io mday-io left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The production fix looks correct: unexpected exchange errors now propagate, while the existing NOT_IMPLEMENTED fallback is preserved.

One nonblocking test simplification: the overwrite-level regression already exercises the real _exchange_tables implementation and catches the swallowed error, plus verifies cleanup. Could we consolidate around that test instead of repeating the same failure at the helper level?

Keep the error-propagation assertion, assert no rename occurs, and verify that the only table dropped across the entire execution trace is the temporary table. Please leave the existing NOT_IMPLEMENTED fallback test intact.

Additionally, please confirm that you ran make style and make fast-test locally

@wolfgang-aura

Copy link
Copy Markdown
Author

Thanks. Pushed a test-only change on top of your merge commit. The helper-level _exchange_tables test is gone, and the overwrite-level test now also asserts that the only DROP across the whole trace is the temporary table. The NOT_IMPLEMENTED fallback test is untouched.

I ran tests/core/engine_adapter/test_clickhouse.py locally (35 passed) and ruff format/check on the file. I did not run make style or make fast-test in full, since this Windows host can't build the full dev environment.

@mday-io

mday-io commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Sorry this sat after your quick turnaround. The consolidated test is what I was after. I checked that it fails on main and passes here, and the branch still merges cleanly with current main.

Two small things before we merge. d9cae3b is missing its DCO sign-off, so git rebase --signoff HEAD~1 and a force-push should fix it. Could you also update the test plan in the description? It still mentions test_exchange_tables_reraises_other_errors and two failures on main.

Once that's pushed I'll start CI.

…e-level test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: wolfgang-aura <169568318+wolfgang-aura@users.noreply.github.com>
@wolfgang-aura
wolfgang-aura force-pushed the fix/clickhouse-exchange-tables-reraise branch from d9cae3b to 3bca554 Compare November 25, 2026 00:54
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ClickHouse adapter now propagates exchange failures other than NOT_IMPLEMENTED instead of treating them as successful insert-overwrite operations. A regression test checks ACCESS_DENIED propagation, confirms that no rename statements run, and verifies temporary-table cleanup.

Changes: ClickHouse exchange error handling

Layer / File(s) Summary
Exchange error handling and regression coverage
sqlmesh/core/engine_adapter/clickhouse.py, tests/core/engine_adapter/test_clickhouse.py
The adapter propagates an ACCESS_DENIED error from EXCHANGE TABLES without running rename statements. The regression test also checks that the temporary target is dropped.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested reviewers: treysp, mday-io, stuffbyyuki

Merge Risk: Minimal · up to 3bca5

ClickHouse table replacement now raises on exchange failures other than NOT_IMPLEMENTED instead of reporting success with stale data. The non-atomic fallback is unchanged. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: ClickHouse EXCHANGE TABLES errors other than NOT_IMPLEMENTED are now re-raised instead of being silently handled. It follows the conventional commit style and is speci…
Description check Passed The description covers the core change, the linked issue (#6087), the reason for the fix, and a detailed test plan naming the new regression test and the unchanged NOT_IMPLEMENTED fallback test. It ex…
Linked Issues check Passed Issue #6087 requires that EXCHANGE TABLES failures other than NOT_IMPLEMENTED propagate from ClickhouseEngineAdapter._exchange_tables, so evaluation fails instead of reporting success over stale…
Out of Scope Changes check Passed The change set has two parts. In sqlmesh/core/engine_adapter/clickhouse.py, the change narrows the exception handling in _exchange_tables, and the rename fallback moves one indent level with uncha…
Full details: Title check

Explanation

The title names the main change: ClickHouse EXCHANGE TABLES errors other than NOT_IMPLEMENTED are now re-raised instead of being silently handled. It follows the conventional commit style and is specific enough for a teammate scanning history. It is 73 characters, which is slightly long but acceptable.

Full details: Description check

Explanation

The description covers the core change, the linked issue (#6087), the reason for the fix, and a detailed test plan naming the new regression test and the unchanged NOT_IMPLEMENTED fallback test. It explains that the non-atomic rename fallback only moved one indent level. The template's Description, Test Plan, and Checklist sections are all present. Gaps: the checklist leaves 'make style' and 'make fast-test' unchecked, and the author states they were not run. The description also does not say whether the reported test status is current, and the objectives note a reviewer flagged an obsolete test name and two main-branch failures in the test plan. These are minor issues that do not make the description incomplete.

Full details: Linked Issues check

Explanation

Issue #6087 requires that EXCHANGE TABLES failures other than NOT_IMPLEMENTED propagate from ClickhouseEngineAdapter._exchange_tables, so evaluation fails instead of reporting success over stale data. The PR description and the AI-generated change summary state that _exchange_tables now re-raises any DatabaseError whose message lacks NOT_IMPLEMENTED, and that only NOT_IMPLEMENTED enters the non-atomic rename fallback. This matches the fix proposed in the issue. The new test test_insert_overwrite_by_condition_replace_exchange_error_propagates covers the reported path: an ACCESS_DENIED error from the non-partitioned replace path propagates out of _insert_overwrite_by_condition. The existing test_exchange_tables covers the NOT_IMPLEMENTED fallback. Limit: the _exchange_tables hunk itself could not be read directly in this review. The repository file view was truncated, and the diff tool reported missing changed blobs. This verdict relies on the PR description and the change summary for that hunk. The issue's optional success-branch test is not a stated requirement.

Full details: Out of Scope Changes check

Explanation

The change set has two parts. In sqlmesh/core/engine_adapter/clickhouse.py, the change narrows the exception handling in _exchange_tables, and the rename fallback moves one indent level with unchanged statements. Both directly implement #6087. In tests/core/engine_adapter/test_clickhouse.py, the change adds a SQL-normalization helper and a regression test for the ACCESS_DENIED propagation. The helper supports that test. No unrelated change was identified in the summaries. The clickhouse.py hunk was not read directly, so this verdict depends on the summary for that hunk.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb956437-3db1-42a4-8bea-34d1b4cf0100
Commits

Reviewing files that changed from the base of the PR and between 1f96a72 and 3bca554.

Files selected for processing: 2

  • sqlmesh/core/engine_adapter/clickhouse.py
  • tests/core/engine_adapter/test_clickhouse.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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.

ClickhouseEngineAdapter._exchange_tables silently swallows non-NOT_IMPLEMENTED swap failures → FULL model reports success over stale data

2 participants