Summary
fabric__get_use_database_sql has no None-guard, so callers that pass database=None (a legitimate dbt-core code path, see below) cause the macro to render USE [None]; — syntactically invalid T-SQL.
Evidence (HEAD 0de2190, v1.10.0)
dbt/include/fabric/macros/adapters/metadata.sql:
{%- macro fabric__get_use_database_sql(database) -%}
USE [{{database | replace('"', '') | replace('[', '') | replace(']', '')}}];
{%- endmacro -%}
If database is the Python value None, Jinja renders it as the string "None".
How database=None happens in practice
This is not a hypothetical. dbt-core's default__drop_schema_named macro builds a relation with no database and hands it to drop_schema:
{% macro default__drop_schema_named(schema_name) %}
{% set schema_relation = api.Relation.create(schema=schema_name) %}
{{ adapter.drop_schema(schema_relation) }}
{% endmacro %}
api.Relation.create(schema=schema_name) creates a relation with relation.database = None because the caller did not specify one. drop_schema then dispatches into fabric__drop_schema, which calls fabric__get_use_database_sql(relation.database) — i.e. fabric__get_use_database_sql(None) — and the macro renders USE [None];.
User-facing triggers for this code path:
dbt run-operation drop_schema_named --args '{schema_name: foo}' — the documented way to drop a schema by name without specifying a database.
- The
BaseDropSchemaNamed test class in dbt-tests-adapter exercises this exact path.
- Any user-authored macro that calls
api.Relation.create(schema=...) without a database arg and then hands the relation to a metadata helper.
User impact
A dbt run-operation drop_schema_named call fails with Invalid object name 'None'. The error appears as a generic T-SQL parsing failure with no obvious connection to dbt's database handling — users typically waste time looking at their schema name or permissions before tracing it back to the macro.
Suggested fix
Wrap the body in a None-guard:
{%- macro fabric__get_use_database_sql(database) -%}
{%- if database is not none -%}
USE [{{ database | replace('"', '') | replace('[', '') | replace(']', '') }}];
{%- endif -%}
{%- endmacro -%}
Reference fix in the fork: commit dea31d36. A PR against this repo will follow.
Summary
fabric__get_use_database_sqlhas no None-guard, so callers that passdatabase=None(a legitimate dbt-core code path, see below) cause the macro to renderUSE [None];— syntactically invalid T-SQL.Evidence (HEAD
0de2190, v1.10.0)dbt/include/fabric/macros/adapters/metadata.sql:If
databaseis the Python valueNone, Jinja renders it as the string"None".How
database=Nonehappens in practiceThis is not a hypothetical. dbt-core's
default__drop_schema_namedmacro builds a relation with no database and hands it todrop_schema:api.Relation.create(schema=schema_name)creates a relation withrelation.database = Nonebecause the caller did not specify one.drop_schemathen dispatches intofabric__drop_schema, which callsfabric__get_use_database_sql(relation.database)— i.e.fabric__get_use_database_sql(None)— and the macro rendersUSE [None];.User-facing triggers for this code path:
dbt run-operation drop_schema_named --args '{schema_name: foo}'— the documented way to drop a schema by name without specifying a database.BaseDropSchemaNamedtest class indbt-tests-adapterexercises this exact path.api.Relation.create(schema=...)without a database arg and then hands the relation to a metadata helper.User impact
A
dbt run-operation drop_schema_namedcall fails withInvalid object name 'None'. The error appears as a generic T-SQL parsing failure with no obvious connection to dbt's database handling — users typically waste time looking at their schema name or permissions before tracing it back to the macro.Suggested fix
Wrap the body in a None-guard:
Reference fix in the fork: commit
dea31d36. A PR against this repo will follow.