Skip to content

Commit

Permalink
improve error message when entry does not have name
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Sep 26, 2024
1 parent d8b1bf5 commit 36148c4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(

Check warning on line 387 in core/dbt/parser/schemas.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/schemas.py#L387

Added line #L387 was not covered by tests
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:
Expand Down
Empty file.
27 changes: 27 additions & 0 deletions tests/functional/parsing_errors/test_parsing_errors.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 36148c4

Please sign in to comment.