diff --git a/.changes/unreleased/Fixes-20220623-082431.yaml b/.changes/unreleased/Fixes-20220623-082431.yaml new file mode 100644 index 00000000000..766e8ed1b38 --- /dev/null +++ b/.changes/unreleased/Fixes-20220623-082431.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Remove duplicate key checking introduced in 1.2.0a1 +time: 2022-06-23T08:24:31.900647+12:00 +custom: + Author: jeremyyeo + Issue: "5331" + PR: "5403" diff --git a/core/dbt/clients/yaml_helper.py b/core/dbt/clients/yaml_helper.py index 1afd8388509..bc0ada41ebb 100644 --- a/core/dbt/clients/yaml_helper.py +++ b/core/dbt/clients/yaml_helper.py @@ -8,7 +8,6 @@ except ImportError: from yaml import Loader, SafeLoader, Dumper # type: ignore # noqa: F401 -from dbt.ui import warning_tag YAML_ERROR_MESSAGE = """ Syntax error near line {line_number} @@ -21,26 +20,6 @@ """.strip() -class UniqueKeyLoader(SafeLoader): - """A subclass that checks for unique yaml mapping nodes. - - This class extends `SafeLoader` from the `yaml` library to check for - unique top level keys (mapping nodes). See issue (https://github.com/yaml/pyyaml/issues/165) - and solution (https://gist.github.com/pypt/94d747fe5180851196eb?permalink_comment_id=4015118). - """ - - def construct_mapping(self, node, deep=False): - mapping = set() - for key_node, value_node in node.value: - key = self.construct_object(key_node, deep=deep) - if key in mapping: - raise dbt.exceptions.DuplicateYamlKeyException( - f"Duplicate {key!r} key found in yaml file" - ) - mapping.add(key) - return super().construct_mapping(node, deep) - - def line_no(i, line, width=3): line_number = str(i).ljust(width) return "{}| {}".format(line_number, line) @@ -69,7 +48,7 @@ def contextualized_yaml_error(raw_contents, error): def safe_load(contents) -> Optional[Dict[str, Any]]: - return yaml.load(contents, Loader=UniqueKeyLoader) + return yaml.load(contents, Loader=SafeLoader) def load_yaml_text(contents, path=None): @@ -82,7 +61,3 @@ def load_yaml_text(contents, path=None): error = str(e) raise dbt.exceptions.ValidationException(error) - except dbt.exceptions.DuplicateYamlKeyException as e: - # TODO: We may want to raise an exception instead of a warning in the future. - e.msg = f"{e} {path.searched_path}/{path.relative_path}." - dbt.exceptions.warn_or_raise(e, log_fmt=warning_tag("{}")) diff --git a/tests/functional/duplications/test_basic_duplications.py b/tests/functional/duplications/test_basic_duplications.py deleted file mode 100644 index 61e3968096f..00000000000 --- a/tests/functional/duplications/test_basic_duplications.py +++ /dev/null @@ -1,33 +0,0 @@ -import pytest - -from dbt.tests.util import run_dbt_and_capture, run_dbt -from dbt.exceptions import DuplicateYamlKeyException - -duplicate_key_schema__schema_yml = """ -version: 2 -models: - - name: my_model -models: - - name: my_model -""" - -my_model_sql = """ - select 1 as fun -""" - - -class TestBasicDuplications: - @pytest.fixture(scope="class") - def models(self): - return { - "my_model.sql": my_model_sql, - "schema.yml": duplicate_key_schema__schema_yml, - } - - def test_warning_in_stdout(self, project): - results, stdout = run_dbt_and_capture(["run"]) - assert "Duplicate 'models' key found in yaml file models/schema.yml" in stdout - - def test_exception_is_raised_with_warn_error_flag(self, project): - with pytest.raises(DuplicateYamlKeyException): - run_dbt(["--warn-error", "run"])