Guard fabric__get_use_database_sql against database=None#396
Open
sdebruyn wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #395.
Summary
Wraps
fabric__get_use_database_sqlin a None-guard so it no longer rendersUSE [None];when called withdatabase=None.Background
dbt-core's
default__drop_schema_namedbuilds a relation viaapi.Relation.create(schema=schema_name)— i.e. without a database — and hands it todrop_schema.fabric__drop_schemathen callsfabric__get_use_database_sql(relation.database), which today is:If
databaseisNone, Jinja renders the string"None", producingUSE [None];— anInvalid object name 'None'T-SQL error.dbt run-operation drop_schema_namedfails, and the error gives no hint about the underlying database handling.Change
Wrap the
USE [...]statement in{% if database is not none %}. WhendatabaseisNonethe macro now renders nothing, leaving the connection's current database context untouched (which is what the caller wants fordrop_schema_named).Test plan
dbt run-operation drop_schema_named --args '{schema_name: foo}'no longer fails withInvalid object name 'None'and drops the schema in the current databasedbt runagainst a model with an explicitdatabase:config still emitsUSE [...]with the correct catalog (existing behaviour unchanged)dbt-tests-adapter'sBaseDropSchemaNamedpasses