Skip to content

Commit

Permalink
deprecate v1 configs
Browse files Browse the repository at this point in the history
Bump included projects to v2
fix tests after removing quoting
  • Loading branch information
Jacob Beck committed Apr 16, 2020
1 parent bc062c9 commit 2618ae9
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 34 deletions.
4 changes: 0 additions & 4 deletions core/dbt/contracts/graph/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,6 @@ def finalize_and_validate(self: T) -> T:
@dataclass
class SourceConfig(BaseConfig):
enabled: bool = True
quoting: Dict[str, Any] = field(
default_factory=dict,
metadata=MergeBehavior.Update.meta(),
)


@dataclass
Expand Down
25 changes: 9 additions & 16 deletions core/dbt/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,16 @@ class ModelsKeyNonModelDeprecation(DBTDeprecation):
'''


class BigQueryPartitionByStringDeprecation(DBTDeprecation):
_name = 'bq-partition-by-string'

_description = '''
As of dbt v0.16.0, the `partition_by` config in BigQuery accepts a
dictionary containing `field` and `data_type`.
- Provided partition_by: {raw_partition_by}
- dbt inferred: {inferred_partition_by}
class DbtProjectYamlDeprecation(DBTDeprecation):
_name = 'dbt-project-yaml-v1'
_description = '''\
The existing dbt_project.yml format has been deprecated. dbt_project.yml
has been upgraded to config version 2. A future version of dbt will remove
support for the existing ("version 1") format.
Documentation for dbt_project.yml version 2 can be found here:
For more information, see:
https://docs.getdbt.com/docs/upgrading-to-0-16-0
DOCS LINK GOES HERE
'''


Expand Down Expand Up @@ -154,7 +147,7 @@ def warn(name, *args, **kwargs):
NotADictionaryDeprecation(),
ColumnQuotingDeprecation(),
ModelsKeyNonModelDeprecation(),
BigQueryPartitionByStringDeprecation(),
DbtProjectYamlDeprecation(),
]

deprecations: Dict[str, DBTDeprecation] = {
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/include/global_project/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

config-version: 2
name: dbt
version: 1.0

Expand Down
4 changes: 4 additions & 0 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dbt.exceptions
import dbt.flags

from dbt import deprecations
from dbt.helper_types import PathSet
from dbt.include.global_project import PACKAGES
from dbt.logger import GLOBAL_LOGGER as logger, DbtProcessState
Expand Down Expand Up @@ -331,6 +332,9 @@ def load_all(
) -> Manifest:
with PARSING_STATE:
projects = root_config.load_dependencies()
for project in projects.values():
if project.config_version == 1:
deprecations.warn('dbt-project-yaml-v1')
loader = cls(root_config, projects, macro_hook)
loader.load(internal_manifest=internal_manifest)
loader.write_parse_results()
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from abc import ABCMeta, abstractmethod
from typing import Type, Union

from dbt import deprecations
from dbt.adapters.factory import register_adapter
from dbt.config import RuntimeConfig, Project
from dbt.config.profile import read_profile, PROFILES_DIR
Expand Down Expand Up @@ -132,6 +133,8 @@ class ConfiguredTask(BaseTask):
ConfigType = RuntimeConfig

def __init__(self, args, config):
if config.config_version == 1:
deprecations.warn('dbt-project-yaml-v1')
super().__init__(args, config)
register_adapter(self.config)

Expand Down
2 changes: 1 addition & 1 deletion plugins/bigquery/dbt/include/bigquery/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

config-version: 2
name: dbt_bigquery
version: 1.0

Expand Down
2 changes: 1 addition & 1 deletion plugins/postgres/dbt/include/postgres/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

config-version: 2
name: dbt_postgres
version: 1.0

Expand Down
2 changes: 1 addition & 1 deletion plugins/redshift/dbt/include/redshift/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

config-version: 2
name: dbt_redshift
version: 1.0

Expand Down
2 changes: 1 addition & 1 deletion plugins/snowflake/dbt/include/snowflake/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

config-version: 2
name: dbt_snowflake
version: 1.0

Expand Down
2 changes: 1 addition & 1 deletion test/integration/001_simple_copy_test/test_simple_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def postgres_profile(self):

@property
def project_config(self):
return {}
return {'config-version': 2}

@use_profile('postgres')
def test_postgres_run_mixed_case(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def packages_config(self):
]
}

def run_dbt(self, *args, **kwargs):
strict = kwargs.pop('strict', False)
kwargs['strict'] = strict
return super().run_dbt(*args, **kwargs)


class TestSimpleDependency(BaseDependencyTest):

Expand Down Expand Up @@ -76,7 +81,7 @@ def test_postgres_no_dependency_paths(self):
# this should work
local_path = os.path.join('local_models', 'my_model.sql')
results = self.run_dbt(
['run', '--models', f'+{local_path}']
['run', '--models', f'+{local_path}'],
)
# should run the dependency and my_model
self.assertEqual(len(results), 2)
Expand All @@ -103,7 +108,7 @@ def models(self):
def test_postgres_missing_dependency(self):
# dbt should raise a dbt exception, not raise a parse-time TypeError.
with self.assertRaises(dbt.exceptions.Exception) as exc:
self.run_dbt(['compile'])
self.run_dbt(['compile'], strict=False)
message = str(exc.exception)
self.assertIn('no_such_dependency', message)
self.assertIn('is undefined', message)
Expand Down Expand Up @@ -230,6 +235,11 @@ def packages_config(self):
]
}

def run_dbt(self, *args, **kwargs):
strict = kwargs.pop('strict', False)
kwargs['strict'] = strict
return super().run_dbt(*args, **kwargs)

@use_profile('postgres')
def test_postgres_local_dependency_same_name(self):
with self.assertRaises(dbt.exceptions.DependencyException):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def packages_config(self):
]
}

def run_dbt(self, cmd=None, *args, **kwargs):
if cmd and cmd[0] != 'deps':
strict = kwargs.pop('strict', False)
kwargs['strict'] = strict
return super().run_dbt(cmd, *args, **kwargs)

def run_deps(self):
return self.run_dbt(["deps"])

Expand Down Expand Up @@ -194,7 +200,7 @@ def packages_config(self):

def deps_run_assert_equality(self):
self.run_dbt(["deps"])
results = self.run_dbt(["run"])
results = self.run_dbt(["run"], strict=False)
self.assertEqual(len(results), 4)

self.assertTablesEqual("seed","table_model")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def schema(self):
def models(self):
return "models"

def run_dbt(self, *args, **kwargs):
strict = kwargs.pop('strict', False)
kwargs['strict'] = strict
return super().run_dbt(*args, **kwargs)

class TestSimpleDependencyWithConfigs(BaseTestSimpleDependencyWithConfigs):
@property
def packages_config(self):
Expand Down
30 changes: 28 additions & 2 deletions test/integration/012_deprecation_tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def schema(self):
def dir(path):
return path.lstrip("/")


class TestDeprecations(BaseTestDeprecations):
@property
def models(self):
return self.dir("models")


class TestDeprecations(BaseTestDeprecations):
@use_profile('postgres')
def test_postgres_deprecations_fail(self):
self.run_dbt(strict=True, expect_pass=False)
Expand Down Expand Up @@ -79,3 +79,29 @@ def test_postgres_deprecations(self):
self.run_dbt(strict=False)
expected = {'models-key-mismatch'}
self.assertEqual(expected, deprecations.active_deprecations)


class TestDbtProjectYamlV1Deprecation(BaseTestDeprecations):
@property
def models(self):
return 'boring-models'

@property
def project_config(self):
# No config-version set!
return {}

@use_profile('postgres')
def test_postgres_project_deprecations_fail(self):
with self.assertRaises(dbt.exceptions.CompilationException) as exc:
self.run_dbt(strict=True)

exc_str = ' '.join(str(exc.exception).split()) # flatten all whitespace
self.assertIn('dbt_project.yml has been upgraded to config version 2', exc_str)

@use_profile('postgres')
def test_postgres_project_deprecations(self):
self.assertEqual(deprecations.active_deprecations, set())
self.run_dbt(strict=False)
expected = {'dbt-project-yaml-v1'}
self.assertEqual(expected, deprecations.active_deprecations)
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,6 @@ def expected_postgres_references_manifest(self, model_database=None):
},
'config': {
'enabled': True,
'quoting': {},
},
'quoting': {
'database': False,
Expand Down
1 change: 0 additions & 1 deletion test/integration/047_dbt_ls_test/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def expect_source_output(self):
'json': {
'config': {
'enabled': True,
'quoting': {},
},
'package_name': 'test',
'name': 'my_table',
Expand Down
1 change: 0 additions & 1 deletion test/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,6 @@ def test_basic(self):
'tags': [],
'config': {
'enabled': True,
'quoting': {},
}
}
source_def = self.ContractType(
Expand Down

0 comments on commit 2618ae9

Please sign in to comment.