From 1751ce0ed109c82bc141c9b0fe6f4ce300817684 Mon Sep 17 00:00:00 2001 From: Bram Neijt Date: Fri, 10 Jun 2022 18:22:34 +0200 Subject: [PATCH] Fix manage_schemas parsing from profile --- core/dbt/config/profile.py | 2 +- core/dbt/task/run.py | 2 ++ .../models/my_first_dbt_model.sql | 12 ------- .../models/schema.yml | 11 ------ .../test_local_dependency.py | 34 ------------------- .../077_schema_management_tests/update.sql | 7 ---- .../test_drop_dangling_models.py | 32 ++++++++--------- 7 files changed, 18 insertions(+), 82 deletions(-) delete mode 100644 test/integration/077_schema_management_tests/models/my_first_dbt_model.sql delete mode 100644 test/integration/077_schema_management_tests/models/schema.yml delete mode 100644 test/integration/077_schema_management_tests/test_local_dependency.py delete mode 100644 test/integration/077_schema_management_tests/update.sql diff --git a/core/dbt/config/profile.py b/core/dbt/config/profile.py index a28b84fd5fb..7e775bf4f39 100644 --- a/core/dbt/config/profile.py +++ b/core/dbt/config/profile.py @@ -360,7 +360,7 @@ def from_raw_profile_info( target_name=target_name, threads=threads, user_config=user_config, - manage_schemas=False, # TODO + manage_schemas=profile_data.get("manage_schemas", False), ) @classmethod diff --git a/core/dbt/task/run.py b/core/dbt/task/run.py index 41da5abcf91..c835977d334 100644 --- a/core/dbt/task/run.py +++ b/core/dbt/task/run.py @@ -24,6 +24,7 @@ from dbt.contracts.results import NodeStatus, RunResult, RunStatus, RunningStatus from dbt.exceptions import ( warn_or_error, + warn, CompilationException, InternalException, RuntimeException, @@ -499,6 +500,7 @@ def manage_schema(self, adapter, results: List[RunResult]): if not manage_schemas_config: # TODO debug not doing anything + warn("Schema's configured to be managed, but manage_schemas is false in the profile") return if len(managed_schemas_actions_config) == 0: diff --git a/test/integration/077_schema_management_tests/models/my_first_dbt_model.sql b/test/integration/077_schema_management_tests/models/my_first_dbt_model.sql deleted file mode 100644 index 3c9ffd00ab3..00000000000 --- a/test/integration/077_schema_management_tests/models/my_first_dbt_model.sql +++ /dev/null @@ -1,12 +0,0 @@ -{{ config(materialized='table') }} - -with source_data as ( - - select 1 as id - union all - select null as id - -) - -select * -from source_data diff --git a/test/integration/077_schema_management_tests/models/schema.yml b/test/integration/077_schema_management_tests/models/schema.yml deleted file mode 100644 index d40e075cea0..00000000000 --- a/test/integration/077_schema_management_tests/models/schema.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: 2 - -models: - - name: my_first_dbt_model - description: "A starter dbt model" - columns: - - name: id - description: "The primary key for this table" - tests: - - unique - - not_null diff --git a/test/integration/077_schema_management_tests/test_local_dependency.py b/test/integration/077_schema_management_tests/test_local_dependency.py deleted file mode 100644 index 4afbd95a5e8..00000000000 --- a/test/integration/077_schema_management_tests/test_local_dependency.py +++ /dev/null @@ -1,34 +0,0 @@ -from test.integration.base import DBTIntegrationTest, use_profile - - -class BaseDependencyTest(DBTIntegrationTest): - @property - def schema(self): - return 'schema_management_077' - - @property - def models(self): - return 'models' - - def base_schema(self): - return self.unique_schema() - - def configured_schema(self): - return self.unique_schema() + '_configured' - - def setUp(self): - super().setUp() - self._created_schemas.add( - self._get_schema_fqn(self.default_database, self.base_schema()) - ) - self._created_schemas.add( - self._get_schema_fqn(self.default_database, self.configured_schema()) - ) - - -class TestSimpleDependency(BaseDependencyTest): - @use_profile('postgres') - def test_postgres_local_dependency(self): - results = self.run_dbt() - self.assertEqual(len(results), 1) - self.assertTableDoesExist("my_frist_dbt_model") diff --git a/test/integration/077_schema_management_tests/update.sql b/test/integration/077_schema_management_tests/update.sql deleted file mode 100644 index a3845ee4110..00000000000 --- a/test/integration/077_schema_management_tests/update.sql +++ /dev/null @@ -1,7 +0,0 @@ - -UPDATE {schema}.seed set first_name = 'Paul', updated_at = now() where id = 500; - -INSERT INTO {schema}.seed - ("id","first_name","email","ip_address","updated_at") -VALUES - (501, 'Steve', 'sthomas@hhs.gov', '6.241.88.251', now()); diff --git a/tests/functional/schema_management/test_drop_dangling_models.py b/tests/functional/schema_management/test_drop_dangling_models.py index 4629fa94a80..fe609057f51 100644 --- a/tests/functional/schema_management/test_drop_dangling_models.py +++ b/tests/functional/schema_management/test_drop_dangling_models.py @@ -1,7 +1,11 @@ import pytest import os -from dbt.tests.util import run_dbt, check_table_does_exist, check_table_does_not_exist, write_file +from dbt.tests.util import ( + run_dbt, + check_table_does_exist, + check_table_does_not_exist, +) model = """ {{ @@ -9,24 +13,18 @@ materialized = "table" ) }} - -with source_data as ( - - select 1 as id -union all -select null as id - -) - -select * -from source_data +SELECT * FROM ( +VALUES (1, 'one'), + (2, 'two'), + (3, 'three') +) AS t (num,letter) """ @pytest.fixture(scope="class") def models(): return { - "users.sql": model, + "numbers.sql": model, } @@ -61,12 +59,12 @@ def test_drop( self, project, ): - # create users model + # create numbers model run_dbt(["run"]) - check_table_does_exist(project.adapter, "users") + check_table_does_exist(project.adapter, "numbers") check_table_does_not_exist(project.adapter, "baz") - # remove users model + # remove numbers model project.update_models({}) run_dbt(["run"]) - check_table_does_not_exist(project.adapter, "users") + check_table_does_not_exist(project.adapter, "numbers")