Skip to content

Commit

Permalink
Fix: Source quoting ignores global configuration (#10905)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk authored Oct 25, 2024
1 parent d07bfda commit 316ecfc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20241023-152054.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Restore source quoting behaviour when quoting config provided in dbt_project.yml
time: 2024-10-23T15:20:54.766893-04:00
custom:
Author: michelleark
Issue: "10892"
9 changes: 8 additions & 1 deletion core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,15 @@ def resolve(self, source_name: str, table_name: str):
target_kind="source",
disabled=(isinstance(target_source, Disabled)),
)

# Source quoting does _not_ respect global configs in dbt_project.yml, as documented here:
# https://docs.getdbt.com/reference/project-configs/quoting
# Use an object with an empty quoting field to bypass any settings in self.
class SourceQuotingBaseConfig:
quoting: Dict[str, Any] = {}

return self.Relation.create_from(
self.config,
SourceQuotingBaseConfig(),
target_source,
limit=self.resolve_limit,
event_time_filter=self.resolve_event_time_filter(target_source),
Expand Down
64 changes: 64 additions & 0 deletions tests/functional/relation_quoting/test_relation_quoting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest

from dbt.tests.util import read_file, run_dbt

_SOURCES_YML = """
sources:
- name: source_name
database: source_database
schema: source_schema
tables:
- name: customers
"""


class TestSourceQuotingGlobalConfigs:
@pytest.fixture(scope="class")
def project_config_update(self):
# Postgres quoting configs are True by default -- turn them all to False to show they are not respected during source rendering
return {
"quoting": {
"database": False,
"schema": False,
"identifier": False,
},
}

@pytest.fixture(scope="class")
def models(self):
return {
"sources.yml": _SOURCES_YML,
"model.sql": "select * from {{ source('source_name', 'customers') }}",
}

def test_sources_ignore_global_quoting_configs(self, project):
run_dbt(["compile"])

generated_sql = read_file("target", "compiled", "test", "models", "model.sql")
assert generated_sql == 'select * from "source_database"."source_schema"."customers"'


class TestModelQuoting:
@pytest.fixture(scope="class")
def project_config_update(self):
# Postgres quoting configs are True by default -- turn them all to False to show they are respected during model rendering
return {
"quoting": {
"database": False,
"schema": False,
"identifier": False,
},
}

@pytest.fixture(scope="class")
def models(self):
return {
"model.sql": "select 1 as id",
"model_downstream.sql": "select * from {{ ref('model') }}",
}

def test_models_respect_global_quoting_configs(self, project):
run_dbt(["compile"])

generated_sql = read_file("target", "compiled", "test", "models", "model_downstream.sql")
assert generated_sql == f"select * from dbt.{project.test_schema}.model"

0 comments on commit 316ecfc

Please sign in to comment.