Compare commits

...

1 Commits

Author SHA1 Message Date
Michelle Ark
36148c49bd improve error message when entry does not have name 2024-09-27 00:47:37 +01:00
3 changed files with 31 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import datetime
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 @@ class YamlReader(metaclass=ABCMeta):
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:

View File

@@ -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"])