Skip to content

Commit

Permalink
[Fix]: remove duplicate key checking (#5403)
Browse files Browse the repository at this point in the history
* remove duplicate key checking

* add changelog
  • Loading branch information
jeremyyeo authored Jun 23, 2022
1 parent d257d0b commit 1cfc085
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 59 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20220623-082431.yaml
Original file line number Diff line number Diff line change
@@ -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"
27 changes: 1 addition & 26 deletions core/dbt/clients/yaml_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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("{}"))
33 changes: 0 additions & 33 deletions tests/functional/duplications/test_basic_duplications.py

This file was deleted.

0 comments on commit 1cfc085

Please sign in to comment.