From ff128078d59f08a9645838f1e61ed10f1f221543 Mon Sep 17 00:00:00 2001 From: Sam Debruyn Date: Tue, 19 May 2026 10:50:43 +0200 Subject: [PATCH] Guard fabric__get_use_database_sql against database=None dbt-core's default__drop_schema_named macro builds a relation with no database and hands it to drop_schema, which dispatches into fabric__drop_schema and ultimately calls fabric__get_use_database_sql with database=None. The macro then renders USE [None]; which is invalid T-SQL, so dbt run-operation drop_schema_named fails. Wrap the USE [...] statement in an is not none guard so the macro renders an empty string when no database is supplied, leaving the current database context untouched. --- dbt/include/fabric/macros/adapters/metadata.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dbt/include/fabric/macros/adapters/metadata.sql b/dbt/include/fabric/macros/adapters/metadata.sql index 6c97a6ba..2b6e533c 100644 --- a/dbt/include/fabric/macros/adapters/metadata.sql +++ b/dbt/include/fabric/macros/adapters/metadata.sql @@ -21,7 +21,9 @@ {% endmacro %} {%- macro fabric__get_use_database_sql(database) -%} - USE [{{database | replace('"', '') | replace('[', '') | replace(']', '')}}]; + {%- if database is not none -%} + USE [{{database | replace('"', '') | replace('[', '') | replace(']', '')}}]; + {%- endif -%} {%- endmacro -%} {% macro fabric__list_schemas(database) %}