From 36148c49bd692cdb2c02d5f0c64c50da18e6af77 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Fri, 27 Sep 2024 00:47:37 +0100 Subject: [PATCH] improve error message when entry does not have name --- core/dbt/parser/schemas.py | 5 +++- tests/functional/parsing_errors/__init__.py | 0 .../parsing_errors/test_parsing_errors.py | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/functional/parsing_errors/__init__.py create mode 100644 tests/functional/parsing_errors/test_parsing_errors.py diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index 6fa73cc3ee9..d9523759c60 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -2,6 +2,7 @@ import time from abc import ABCMeta, abstractmethod from dataclasses import dataclass, field +from pprint import pformat from typing import Any, Callable, Dict, Generic, Iterable, List, Optional, Type, TypeVar from dbt.artifacts.resources import RefArgs @@ -383,7 +384,9 @@ def get_key_dicts(self) -> Iterable[Dict[str, Any]]: raise YamlParseListError(path, self.key, data, "expected a dict with string keys") if "name" not in entry and "model" not in entry: - raise ParsingError("Entry did not contain a name") + raise ParsingError( + f"Entry in '{self.yaml.path.original_file_path}' did not contain a name:\n{pformat(entry, sort_dicts=False)}" + ) unrendered_config = {} if "config" in entry: diff --git a/tests/functional/parsing_errors/__init__.py b/tests/functional/parsing_errors/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/functional/parsing_errors/test_parsing_errors.py b/tests/functional/parsing_errors/test_parsing_errors.py new file mode 100644 index 00000000000..cdd0c32fa0b --- /dev/null +++ b/tests/functional/parsing_errors/test_parsing_errors.py @@ -0,0 +1,27 @@ +import pytest + +from dbt.exceptions import ParsingError +from dbt.tests.util import run_dbt + +schema_yml_model_no_name = """ +data_tests: + - description: "{{ doc('my_singular_test_documentation') }}" + config: + error_if: ">10" + meta: + some_key: some_val +""" + + +class TestParsingErrors: + @pytest.fixture(scope="class") + def models(self): + return { + "schema.yml": schema_yml_model_no_name, + } + + def test_parsing_error_no_entry_name(self, project): + with pytest.raises( + ParsingError, match="Entry in 'models/schema.yml' did not contain a name" + ): + run_dbt(["parse"])