Skip to content

fix: restore schema detection with distinct database names - #834

Open
samhoon000 wants to merge 2 commits into
ClickHouse:mainfrom
samhoon000:fix/schema-exists-database-alias
Open

samhoon000 wants to merge 2 commits into
ClickHouse:mainfrom
samhoon000:fix/schema-exists-database-alias

Conversation

@samhoon000

@samhoon000 samhoon000 commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

Restore adapter.check_schema_exists(database, schema) for callers that pass different names. Fixes #831.

dbt Core's implementation constructs an information-schema relation before dispatching the lookup. ClickHouse uses the dbt schema as its database name, so a different logical database name caused relation construction to raise. The adapter now normalizes the database argument at this entry point and delegates to dbt's existing lookup macro.

Testing

  • python -m pytest -q --confcutdir=tests/unit tests/unit — 158 passed. The new tests reproduce the exception on the base branch and cover existing and missing schemas with matching, absent, and differing database arguments.
  • Ruff formatting and lint, mypy, and yamllint passed. YAML was checked using the repository's LF bytes.
  • The integration test exercises the Jinja adapter method with an explicit database name different from the schema. Local integration setup requires a ClickHouse server and the test configuration calls time.tzset(), which is unavailable on Windows.

Checklist

  • Unit and integration tests cover the affected cases.
  • The unreleased changelog describes the fix.

Note

Low Risk
Small, targeted adapter override for schema lookup with added unit and integration tests; no auth or data-path changes.

Overview
Restores adapter.check_schema_exists(database, schema) when dbt packages pass a logical database name that differs from the ClickHouse database (the dbt schema). The adapter now overrides the method and calls the parent lookup with (schema, schema), so relation construction no longer fails and existence is still checked against system.databases via the existing macro.

Tests: integration coverage now exercises Jinja calls with an explicit mismatched database name; new unit tests assert the macro always receives the schema as the lookup key regardless of the database argument.

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

@cla-assistant

cla-assistant Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@koletzilla koletzilla self-assigned this Nov 27, 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.

1.10.4: check_schema_exists raises 'Cannot set database' when database differs from schema

2 participants