Skip to content

Fix catalog restoration after failed adapter operations - #6114

Open
lllleolin-max wants to merge 1 commit into
SQLMesh:mainfrom
lllleolin-max:fix/catalog-restoration-20261003
Open

lllleolin-max wants to merge 1 commit into
SQLMesh:mainfrom
lllleolin-max:fix/catalog-restoration-20261003

Conversation

@lllleolin-max

Copy link
Copy Markdown

Description

An operation on an explicitly qualified catalog can leave the adapter using that catalog when the operation raises. A later unqualified statement then runs in the wrong catalog. For example, a failing metadata query for an attached DuckDB catalog currently causes the next unqualified CREATE TABLE to create its table there instead of in the original catalog.

Restore the previous catalog in finally around the temporarily switched operation. Successful return values and the existing paths that require no switch are preserved. When restoration succeeds, the original operation exception propagates unchanged. If restoration itself fails, its exception propagates with the operation error retained as context.

The production change is confined to set_catalog; tests exercise actual DuckDB placement after an error, positional/keyword table and schema arguments, nested operations, unchanged input expressions, and restoration failure.

Test Plan

  • New real DuckDB regressions: 2 failures on baseline, 2 passes after the fix. Decorator and database regressions together: 16 passed.
  • Local engine-adapter suite excluding external-engine integration: 705 passed, 2 skipped.
  • Full fast-test marker phases were run. Windows fixture-copy errors and dbt failures reproduce on the unchanged baseline; the candidate introduces no additional failing test IDs. The suite is not claimed to be fully green locally.
  • Ruff lint and format passed. Full mypy has the unchanged Windows signal.SIGUSR1 error, confirmed on baseline. The migration-number script passed under Git Bash; its pre-commit /bin/bash invocation is unavailable on this Windows host.

AI assistance was used for implementation and validation, with a separate independent code review and executable regression checks.

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

The unchecked validation items reflect the baseline environment limitations above; no check configuration was relaxed.

Signed-off-by: lllleolin-max <244385774+lllleolin-max@users.noreply.github.com>
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.

1 participant