Skip to content

fix: return no database for ClickHouse in get_package_database_and_schema - #1107

Merged
EladBarkay merged 2 commits into
masterfrom
fix-clickhouse-package-database
Dec 1, 2026
Merged

EladBarkay merged 2 commits into
masterfrom
fix-clickhouse-package-database

Conversation

@EladBarkay

@EladBarkay EladBarkay commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On dbt-clickhouse 1.10.4, every dbt test with the Elementary package fails with Cannot set database <schema> in clickhouse!.

clickhouse__get_package_database_and_schema returns [schema, schema], so it makes up a database equal to the schema. get_elementary_tests_schema then calls adapter.check_schema_exists(<schema>, <schema>__tests). dbt-clickhouse 1.10.4 (ClickHouse/dbt-clickhouse#797) removed its check_schema_exists override, so the call reaches SQLAdapter.check_schema_exists. That builds a ClickHouseRelation with database != schema, which ClickHouseRelation.__post_init__ rejects. Upstream issue: ClickHouse/dbt-clickhouse#831.

Fix

ClickHouse has no database level: the dbt schema is the ClickHouse database, and ClickHouseRelation always resets path.database to ''. Returning [none, schema] matches what other adapters without a database level get (Spark returns None). All callers either build relations from the value, which dbt-clickhouse normalizes to '', or ignore it on ClickHouse.

The one direct use of the value on ClickHouse was dbname in the generated CLI profile. That line is removed: dbt-clickhouse has no dbname field (no alias either), so it was always ignored, and existing profiles that still contain it keep working.

This also fixes create_elementary_tests_schema when tests_schema_name is set, because it builds Relation.create(database=<schema>, schema=<schema><suffix>), which fails on every dbt-clickhouse version.

Alternative to #1102: this removes the made-up database instead of special-casing check_schema_exists for ClickHouse.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • ClickHouse connection details now use the schema without including a separate database name.
    • Package metadata now reports the schema in the correct field and leaves the database field empty. This avoids showing the schema as both the database and schema.

…hema

ClickHouse has no database level, and dbt-clickhouse 1.10.4 rejects a
relation whose database differs from its schema. Returning the schema as
the database made check_schema_exists(<schema>, <schema>__tests) raise
'Cannot set database ... in clickhouse!' on every dbt test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ClickHouse profile arguments no longer include dbname. Package database and schema lookup now returns none for the database and the model schema for the schema.

Changes: ClickHouse database and schema mapping

Layer / File(s) Summary
Align profile arguments and package lookup
macros/utils/cross_db_utils/generate_elementary_profile_args.sql, macros/utils/graph/get_package_database_and_schema.sql
The profile arguments omit dbname. Package lookup returns none for the database and the model schema for the schema.

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

Possibly related PRs

Suggested reviewers: guyeshdat

Merge Risk: Minimal · up to 17e7b

This change makes ClickHouse package database and schema resolution consistent with ClickHouse having no separate database level, which fixes dbt test failures. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: ClickHouse's get_package_database_and_schema now returns no database instead of the schema in both positions. The raw summary confirms this change in get_package_datab…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: ClickHouse's get_package_database_and_schema now returns no database instead of the schema in both positions. The raw summary confirms this change in get_package_database_and_schema.sql. The removal of dbname from the ClickHouse profile args is a secondary change that the title does not mention, but the title still describes the primary fix accurately.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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: Essentials
  • Run ID: f765a459-0e49-4bae-af6b-116707c6c38f
Commits

Reviewing files that changed from the base of the PR and between e8aa4b9 and 17e7b9d.

Files selected for processing: 2

  • macros/utils/cross_db_utils/generate_elementary_profile_args.sql
  • macros/utils/graph/get_package_database_and_schema.sql
Files with no reviewable changes: 1

  • macros/utils/cross_db_utils/generate_elementary_profile_args.sql

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

@github-actions

Copy link
Copy Markdown
Contributor

👋 @EladBarkay
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@jonlevine7

jonlevine7 commented Nov 30, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

dbt-clickhouse has no dbname field and no database level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EladBarkay
EladBarkay merged commit f79febb into master Dec 1, 2026
32 of 33 checks passed
@EladBarkay
EladBarkay deleted the fix-clickhouse-package-database branch December 1, 2026 09:30
EladBarkay added a commit that referenced this pull request Dec 1, 2026
Resolve conflict with #1107: keep secure/verify, drop dbname.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

3 participants