Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit f6b866b

Browse files
Fix adapter.get_relation to find quoted case-sensitive relations
1 parent b687ac4 commit f6b866b

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

dbt/adapters/snowflake/impl.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,33 @@ def _catalog_filter_table(
112112
return super()._catalog_filter_table(lowered, used_schemas)
113113

114114
def _make_match_kwargs(self, database, schema, identifier):
115+
# if any path part is already quoted then consider same casing but without quotes
115116
quoting = self.config.quoting
116-
if identifier is not None and quoting["identifier"] is False:
117+
if SnowflakeAdapter._is_quoted(identifier):
118+
identifier = identifier.strip(SnowflakeRelation.quote_character)
119+
elif identifier is not None and quoting["identifier"] is False:
117120
identifier = identifier.upper()
118121

119-
if schema is not None and quoting["schema"] is False:
122+
if SnowflakeAdapter._is_quoted(schema):
123+
schema = schema.strip(SnowflakeRelation.quote_character)
124+
elif schema is not None and quoting["schema"] is False:
120125
schema = schema.upper()
121126

122-
if database is not None and quoting["database"] is False:
127+
if SnowflakeAdapter._is_quoted(database):
128+
database = database.strip(SnowflakeRelation.quote_character)
129+
elif database is not None and quoting["database"] is False:
123130
database = database.upper()
124131

125132
return filter_null_values(
126133
{"identifier": identifier, "schema": schema, "database": database}
127134
)
128135

136+
@classmethod
137+
def _is_quoted(cls, identifier: str) -> bool:
138+
return (identifier is not None
139+
and identifier.startswith(SnowflakeRelation.quote_character)
140+
and identifier.endswith(SnowflakeRelation.quote_character))
141+
129142
def _get_warehouse(self) -> str:
130143
_, table = self.execute("select current_warehouse() as warehouse", fetch=True)
131144
if len(table) == 0 or len(table[0]) == 0:

tests/unit/test_snowflake_adapter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,30 @@ def test_authenticator_private_key_string_authentication_no_passphrase(
718718
]
719719
)
720720

721+
def test_get_relation_without_quotes(self):
722+
with mock.patch.object(self.adapter, "list_relations") as list_relations:
723+
list_relations.return_value = [
724+
SnowflakeAdapter.Relation.create(
725+
database="TEST_DATABASE",
726+
schema="test_schema",
727+
identifier="TEST_TABLE"
728+
)
729+
]
730+
relation = self.adapter.get_relation("test_database", "test_schema", "test_table")
731+
assert relation.render() == "TEST_DATABASE.test_schema.TEST_TABLE"
732+
733+
def test_get_relation_with_quotes(self):
734+
with mock.patch.object(self.adapter, "list_relations") as list_relations:
735+
list_relations.return_value = [
736+
SnowflakeAdapter.Relation.create(
737+
database="test_database",
738+
schema="test_schema",
739+
identifier="test_TABLE"
740+
)
741+
]
742+
relation = self.adapter.get_relation("\"test_database\"", "test_schema", "\"test_TABLE\"")
743+
assert relation.render() == "test_database.test_schema.test_TABLE"
744+
721745

722746
class TestSnowflakeAdapterConversions(TestAdapterConversions):
723747
def test_convert_text_type(self):

0 commit comments

Comments
 (0)