Skip to content

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

Merged
mday-io merged 4 commits into
SQLMesh:mainfrom
wolfgang-aura:fix/clickhouse-exchange-tables-reraise
Nov 25, 2026
Merged

mday-io merged 4 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
Contributor

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.

Summary by CodeRabbit

  • Bug Fixes
    • Operations that replace tables now report access or other database errors instead of silently continuing.
    • Temporary tables are cleaned up when a replacement fails, and an unsupported-operation fallback is used only when the database indicates it is needed.

…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
Contributor 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 TABLES errors other than NOT_IMPLEMENTED. A regression test checks ACCESS_DENIED propagation, temporary-table cleanup, and the absence of rename statements.

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 non-NOT_IMPLEMENTED exchange errors instead of running the rename fallback. The regression test verifies ACCESS_DENIED propagation, temporary-target cleanup, and no rename statements.

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 d936f

ClickHouse swap failures other than NOT_IMPLEMENTED now fail model evaluation instead of silently leaving stale data. The NOT_IMPLEMENTED fallback is preserved, and a regression test covers the new behavior. No merge-blocking risk is evident.

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 swallowed. It follows a conventional commit format and is specific to the cha…
Description check Passed The description covers the problem, the fix, and a test plan. It names the new regression test and reports local results. It also states that the checklist items for make style and make fast-test were…
Linked Issues check Passed [#6087] requires that a EXCHANGE TABLES failure other than NOT_IMPLEMENTED propagate from ClickhouseEngineAdapter._exchange_tables, so the evaluation fails instead of succeeding over stale data.…
Out of Scope Changes check Passed The whole-PR diff has two source changes. In clickhouse.py, the _exchange_tables exception handling is narrowed to re-raise non-NOT_IMPLEMENTED errors, and the rename fallback moves one indent l…
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 swallowed. It follows a conventional commit format and is specific to the changeset.

Full details: Description check

Explanation

The description covers the problem, the fix, and a test plan. It names the new regression test and reports local results. It also states that the checklist items for make style and make fast-test were not run. The template's Description, Test Plan, and Checklist sections are all present. The author's checklist marks for the style and full test runs are unchecked, which is accurate, but those gaps are noted for the reviewer.

Full details: Linked Issues check

Explanation

[#6087] requires that a EXCHANGE TABLES failure other than NOT_IMPLEMENTED propagate from ClickhouseEngineAdapter._exchange_tables, so the evaluation fails instead of succeeding over stale data. The whole-PR diff (mergeBase to head) of sqlmesh/core/engine_adapter/clickhouse.py now reads: if "NOT_IMPLEMENTED" not in str(e): raise. Only NOT_IMPLEMENTED reaches the non-atomic rename fallback, and the fallback statements are unchanged apart from indentation. This matches the fix proposed in the issue. The new test test_insert_overwrite_by_condition_replace_exchange_error_propagates in tests/core/engine_adapter/test_clickhouse.py makes EXCHANGE TABLES raise ACCESS_DENIED. It asserts that _insert_overwrite_by_condition re-raises the error, that no RENAME runs, and that the only DROP is the temporary table. The issue's optional success-branch test is not a stated requirement. The previous review could not read the clickhouse.py hunk. This review read it directly, so the earlier limit is resolved. Test execution results were not independently verified; the PR author reports 35 passing tests.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff has two source changes. In clickhouse.py, the _exchange_tables exception handling is narrowed to re-raise non-NOT_IMPLEMENTED errors, and the rename fallback moves one indent level. Both implement #6087. In tests/core/engine_adapter/test_clickhouse.py, the change adds the _executed_sql helper and the ACCESS_DENIED regression test. The helper is used only by that regression test, so it supports the objective. The existing test_exchange_tables is not edited. No unrelated change was found in the diff.

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: f2cf003c-db78-4e28-9d2d-02c5aeb35dce
Commits

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

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.

@mday-io
mday-io merged commit 9c2ad4f into SQLMesh:main Nov 25, 2026
37 checks passed
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