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
  • Loading branch information
Jacob Beck committed Apr 20, 2020
1 parent 1adf994 commit c6b2346
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 48 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 All @@ -123,6 +128,11 @@ def project_config(self):
return {
'config-version': 2,
'macro-paths': ['schema_override_macros'],
'models': {
'config': {
'schema': 'dbt_test',
},
},
'seeds': {
'config': {
'schema': 'dbt_test',
Expand Down Expand Up @@ -230,6 +240,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
1 change: 1 addition & 0 deletions test/integration/009_data_tests_test/test_data_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestDataTests(DBTIntegrationTest):
@property
def project_config(self):
return {
'config-version': 2,
"test-paths": [self.test_path]
}

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
5 changes: 4 additions & 1 deletion test/integration/034_redshift_test/test_late_binding_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ def models(self):
@property
def project_config(self):
return {
'config-version': 2,
'data-paths': [self.dir('seed')],
'seeds': {
'quote_columns': False,
'config': {
'quote_columns': False,
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,22 @@ def run_database_override(self):
func = lambda x: x

self.use_default_project({
'config-version': 2,
'vars': {
'alternate_db': self.alternative_database,
},
'models': {
'vars': {
'alternate_db': self.alternative_database,
'config': {
'database': self.alternative_database,
},
'database': self.alternative_database,
'test': {
'subfolder': {
'database': self.default_database,
},
},
}
'config': {
'database': self.default_database,
}
}
}
},
})
self.run_dbt_notstrict(['seed'])

Expand Down Expand Up @@ -149,7 +154,12 @@ def run_database_override(self):
func = lambda x: x

self.use_default_project({
'seeds': {'database': self.alternative_database}
'config-version': 2,
'seeds': {
'config': {
'database': self.alternative_database
},
},
})
self.run_dbt_notstrict(['seed'])

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
2 changes: 1 addition & 1 deletion test/integration/048_rpc_test/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ServerProcess(dbt.flags.MP_CONTEXT.Process):
def __init__(self, port, profiles_dir, cli_vars=None):
self.port = port
handle_and_check_args = [
'--strict', 'rpc', '--log-cache-events',
'rpc', '--log-cache-events',
'--port', str(self.port),
'--profiles-dir', profiles_dir
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: view_adapter_override
version: '1.0'
macro-paths: ['macros']
config-version: 2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: view_adapter_override
version: '1.0'
macro-paths: ['macros']
config-version: 2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: view_default_override
config-version: 2
version: '1.0'
macro-paths: ['macros']
6 changes: 3 additions & 3 deletions test/rpc/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def test_rpc_seed_threads(
project_root, profiles_root, postgres_profile, unique_schema
):
project = ProjectDefinition(
project_data={'seeds': {'quote_columns': False}},
project_data={'seeds': {'config': {'quote_columns': False}}},
seeds={'data.csv': 'a,b\n1,hello\n2,goodbye'},
)
querier_ctx = get_querier(
Expand All @@ -626,7 +626,7 @@ def test_rpc_seed_include_exclude(
project_root, profiles_root, postgres_profile, unique_schema
):
project = ProjectDefinition(
project_data={'seeds': {'quote_columns': False}},
project_data={'seeds': {'config': {'quote_columns': False}}},
seeds={
'data_1.csv': 'a,b\n1,hello\n2,goodbye',
'data_2.csv': 'a,b\n1,data',
Expand Down Expand Up @@ -773,7 +773,7 @@ def test_source_freshness(
error_me = start_time - timedelta(days=2)
# this should trigger a 'warn'
project = ProjectDefinition(
project_data={'seeds': {'quote_columns': False}},
project_data={'seeds': {'config': {'quote_columns': False}}},
seeds={
'source.csv': 'a,b\n1,{}\n'.format(error_me.strftime('%Y-%m-%d %H:%M:%S')),
'other_source.csv': 'a,b\n1,{}\n'.format(error_me.strftime('%Y-%m-%d %H:%M:%S'))
Expand Down
Loading

0 comments on commit c6b2346

Please sign in to comment.