From 46f7b0c6cb2bf5a60649b2b9d8adf358570e8251 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 22 Oct 2024 15:45:13 -0400 Subject: [PATCH 1/3] TestSourceQuotingLegacy --- .../relation_quoting/test_relation_quoting.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/functional/relation_quoting/test_relation_quoting.py diff --git a/tests/functional/relation_quoting/test_relation_quoting.py b/tests/functional/relation_quoting/test_relation_quoting.py new file mode 100644 index 00000000000..10817c2222f --- /dev/null +++ b/tests/functional/relation_quoting/test_relation_quoting.py @@ -0,0 +1,37 @@ +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 TestSourceQuotingLegacy: + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "quoting": { + "database": True, + "schema": True, + "database": True, + }, + } + + @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" From 227dcd9cf7a2b1239b8723bfc32dddff25410250 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 22 Oct 2024 18:26:27 -0400 Subject: [PATCH 2/3] fix TestSourceQuotingLegacy --- .../functional/relation_quoting/test_relation_quoting.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/functional/relation_quoting/test_relation_quoting.py b/tests/functional/relation_quoting/test_relation_quoting.py index 10817c2222f..5dfa40bbb87 100644 --- a/tests/functional/relation_quoting/test_relation_quoting.py +++ b/tests/functional/relation_quoting/test_relation_quoting.py @@ -15,11 +15,12 @@ class TestSourceQuotingLegacy: @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": True, - "schema": True, - "database": True, + "database": False, + "schema": False, + "database": False, }, } @@ -34,4 +35,4 @@ 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" + assert generated_sql == 'select * from "source_database"."source_schema"."customers"' From 991b26574bef35d0468fbb107efa01264ce6aaec Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 24 Oct 2024 17:38:15 -0400 Subject: [PATCH 3/3] tests for model quoting --- .../relation_quoting/test_relation_quoting.py | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/functional/relation_quoting/test_relation_quoting.py b/tests/functional/relation_quoting/test_relation_quoting.py index 5dfa40bbb87..55f492cc080 100644 --- a/tests/functional/relation_quoting/test_relation_quoting.py +++ b/tests/functional/relation_quoting/test_relation_quoting.py @@ -12,7 +12,7 @@ """ -class TestSourceQuotingLegacy: +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 @@ -20,7 +20,7 @@ def project_config_update(self): "quoting": { "database": False, "schema": False, - "database": False, + "identifier": False, }, } @@ -36,3 +36,29 @@ def test_sources_ignore_global_quoting_configs(self, project): 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"