diff --git a/core/dbt/deprecations.py b/core/dbt/deprecations.py index baf92043cf5..047453f0d20 100644 --- a/core/dbt/deprecations.py +++ b/core/dbt/deprecations.py @@ -36,6 +36,17 @@ class SeedDropExistingDeprecation(DBTDeprecation): will be removed in a future version of dbt.""" +class GenerateSchemaNameSingleArgDeprecated(DBTDeprecation): + name = 'generate-schema-name-single-arg' + description = '''As of dbt v0.14.0, the `generate_schema_name` macro + accepts a second "node" argument. The one-argument form of `generate_schema_name` + is deprecated, and will become unsupported in a future release. + + For more information, see: + https://docs.getdbt.com/v0.14/docs/upgrading-to-014 + ''' # noqa + + _adapter_renamed_description = """\ The adapter function `adapter.{old_name}` is deprecated and will be removed in a future release of dbt. Please use `adapter.{new_name}` instead. @@ -72,6 +83,7 @@ def warn(name, *args, **kwargs): deprecations_list = [ DBTRepositoriesDeprecation(), SeedDropExistingDeprecation(), + GenerateSchemaNameSingleArgDeprecated(), ] deprecations = {d.name: d for d in deprecations_list} diff --git a/core/dbt/exceptions.py b/core/dbt/exceptions.py index d3dd355f647..a2034ac6f7e 100644 --- a/core/dbt/exceptions.py +++ b/core/dbt/exceptions.py @@ -652,16 +652,10 @@ def raise_not_implemented(msg): raise NotImplementedException(msg) -_REPEAT_MESSAGE_CACHE = set() - - -def warn_or_error(msg, node=None, log_fmt=None, repeat=True): +def warn_or_error(msg, node=None, log_fmt=None): if dbt.flags.WARN_ERROR: raise_compiler_error(msg, node) else: - if not repeat and msg in _REPEAT_MESSAGE_CACHE: - return - _REPEAT_MESSAGE_CACHE.add(msg) if log_fmt is not None: msg = log_fmt.format(msg) logger.warning(msg) diff --git a/core/dbt/parser/base.py b/core/dbt/parser/base.py index 39cb9d0887d..ab6c8990bb0 100644 --- a/core/dbt/parser/base.py +++ b/core/dbt/parser/base.py @@ -13,6 +13,7 @@ from dbt.logger import GLOBAL_LOGGER as logger from dbt.contracts.graph.parsed import ParsedNode from dbt.parser.source_config import SourceConfig +from dbt import deprecations class BaseParser(object): @@ -218,10 +219,7 @@ def _update_parsed_node_info(self, parsed_node, config): ) if too_many_args not in str(exc): raise - msg = ('The generate_schema_name macro does not accept a second ' - 'argument. This form is deprecated as of 0.14.0') - dbt.exceptions.warn_or_error(msg, node=parsed_node, repeat=False, - log_fmt='WARNING: {}') + deprecations.warn('generate-schema-name-single-arg') schema = get_schema(schema_override) parsed_node.schema = schema.strip() diff --git a/test/integration/006_simple_dependency_test/schema_override_legacy_macros/schema.sql b/test/integration/006_simple_dependency_test/schema_override_legacy_macros/schema.sql deleted file mode 100644 index b2456437d31..00000000000 --- a/test/integration/006_simple_dependency_test/schema_override_legacy_macros/schema.sql +++ /dev/null @@ -1,6 +0,0 @@ - -{% macro generate_schema_name(schema_name) -%} - - {{ schema_name }}_{{ target.schema }}_macro - -{%- endmacro %} diff --git a/test/integration/006_simple_dependency_test/test_local_dependency.py b/test/integration/006_simple_dependency_test/test_local_dependency.py index 6c2a5ca20bd..e98075b2c24 100644 --- a/test/integration/006_simple_dependency_test/test_local_dependency.py +++ b/test/integration/006_simple_dependency_test/test_local_dependency.py @@ -116,34 +116,6 @@ def test_postgres_local_dependency_out_of_date_no_check(self, mock_get): self.assertEqual(len(results), 3) -class TestDependencyWithLegacySchema(BaseDependencyTest): - @property - def project_config(self): - return { - 'macro-paths': ['test/integration/006_simple_dependency_test/schema_override_legacy_macros'], - 'models': { - 'schema': 'dbt_test', - } - } - - def base_schema(self): - return 'dbt_test_{}_macro'.format(self.unique_schema()) - - def configured_schema(self): - return 'configured_{}_macro'.format(self.unique_schema()) - - @use_profile('postgres') - @mock.patch('dbt.config.project.get_installed_version') - def test_postgres_local_dependency_out_of_date_no_check_no_strict(self, mock_get): - mock_get.return_value = dbt.semver.VersionSpecifier.from_version_string('0.0.1') - self.run_dbt(['deps']) - results = self.run_dbt(['run', '--no-version-check'], strict=False) - self.assertEqual(len(results), 3) - - with self.assertRaises(dbt.exceptions.CompilationException): - results = self.run_dbt(['run', '--no-version-check']) - - class TestSimpleDependencyHooks(DBTIntegrationTest): @property def schema(self): diff --git a/test/integration/012_deprecation_tests/boring-models/boring.sql b/test/integration/012_deprecation_tests/boring-models/boring.sql new file mode 100644 index 00000000000..43258a71464 --- /dev/null +++ b/test/integration/012_deprecation_tests/boring-models/boring.sql @@ -0,0 +1 @@ +select 1 as id diff --git a/test/integration/012_deprecation_tests/macros/schema.sql b/test/integration/012_deprecation_tests/macros/schema.sql new file mode 100644 index 00000000000..d3884257ad6 --- /dev/null +++ b/test/integration/012_deprecation_tests/macros/schema.sql @@ -0,0 +1,7 @@ +{% macro generate_schema_name(schema_name) -%} + {%- if schema_name is none -%} + {{ target.schema }} + {%- else -%} + {{ schema_name }} + {%- endif -%} +{%- endmacro %} diff --git a/test/integration/012_deprecation_tests/test_deprecations.py b/test/integration/012_deprecation_tests/test_deprecations.py index d1a75d1c0bd..7a9d6249270 100644 --- a/test/integration/012_deprecation_tests/test_deprecations.py +++ b/test/integration/012_deprecation_tests/test_deprecations.py @@ -4,9 +4,9 @@ import dbt.exceptions -class TestDeprecations(DBTIntegrationTest): +class BaseTestDeprecations(DBTIntegrationTest): def setUp(self): - super(TestDeprecations, self).setUp() + super(BaseTestDeprecations, self).setUp() deprecations.reset_deprecations() @property @@ -21,6 +21,8 @@ def dir(path): 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) @@ -29,5 +31,29 @@ def test_postgres_deprecations_fail(self): def test_postgres_deprecations(self): self.assertEqual(deprecations.active_deprecations, set()) self.run_dbt(strict=False) - self.assertEqual({'adapter:already_exists'}, - deprecations.active_deprecations) + expected = {'adapter:already_exists'} + self.assertEqual(expected, deprecations.active_deprecations) + + +class TestMacroDeprecations(BaseTestDeprecations): + @property + def models(self): + return self.dir('boring-models') + + @property + def project_config(self): + return { + 'macro-paths': [self.dir('macros')], + } + + @use_profile('postgres') + def test_postgres_deprecations_fail(self): + with self.assertRaises(dbt.exceptions.CompilationException): + self.run_dbt(strict=True) + + @use_profile('postgres') + def test_postgres_deprecations(self): + self.assertEqual(deprecations.active_deprecations, set()) + self.run_dbt(strict=False) + expected = {'generate-schema-name-single-arg'} + self.assertEqual(expected, deprecations.active_deprecations)