Skip to content

Commit

Permalink
Make version configs optional (#7060)
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-connors-3 authored Mar 10, 2023
1 parent 5a0e776 commit 9090268
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 64 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230227-091316.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: make version configs optional
time: 2023-02-27T09:13:16.104386-06:00
custom:
Author: dave-connors-3
Issue: "7054"
7 changes: 0 additions & 7 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,6 @@ def from_project_root(
) -> "PartialProject":
project_root = os.path.normpath(project_root)
project_dict = load_raw_project(project_root)
config_version = project_dict.get("config-version", 1)
if config_version != 2:
raise DbtProjectError(
f"Invalid config version: {config_version}, expected 2",
path=os.path.join(project_root, "dbt_project.yml"),
)

packages_dict = package_data_from_root(project_root)
selectors_dict = selector_data_from_root(project_root)
return cls.from_dicts(
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class RegistryPackageMetadata(
@dataclass
class Project(HyphenatedDbtClassMixin, Replaceable):
name: Identifier
config_version: int
config_version: Optional[int] = 2
version: Optional[Union[SemverString, float]] = None
project_root: Optional[str] = None
source_paths: Optional[List[str]] = None
Expand Down
26 changes: 0 additions & 26 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2092,32 +2092,6 @@ def get_message(self) -> str:
return msg


class PropertyYMLMissingVersionError(PropertyYMLError):
def __init__(self, path: str):
self.path = path
self.issue = f"the yml property file {self.path} is missing a version tag"
super().__init__(self.path, self.issue)


class PropertyYMLVersionNotIntError(PropertyYMLError):
def __init__(self, path: str, version: Any):
self.path = path
self.version = version
self.issue = (
"its 'version:' tag must be an integer (e.g. version: 2)."
f" {self.version} is not an integer"
)
super().__init__(self.path, self.issue)


class PropertyYMLInvalidTagError(PropertyYMLError):
def __init__(self, path: str, version: int):
self.path = path
self.version = version
self.issue = f"its 'version:' tag is set to {self.version}. Only 2 is supported"
super().__init__(self.path, self.issue)


class RelationWrongTypeError(CompilationError):
def __init__(self, relation, expected_type, model=None):
self.relation = relation
Expand Down
3 changes: 1 addition & 2 deletions core/dbt/parser/read_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from dbt.config import Project
from dbt.dataclass_schema import dbtClassMixin
from dbt.parser.schemas import yaml_from_file, schema_file_keys, check_format_version
from dbt.parser.schemas import yaml_from_file, schema_file_keys
from dbt.exceptions import ParsingError
from dbt.parser.search import filesystem_search
from typing import Optional, Dict, List, Mapping
Expand Down Expand Up @@ -87,7 +87,6 @@ def load_source_file(
# Check version, that key values are lists and that each element in
# the lists has a 'name' key
def validate_yaml(file_path, dct):
check_format_version(file_path, dct)
for key in schema_file_keys:
if key in dct:
if not isinstance(dct[key], list):
Expand Down
17 changes: 0 additions & 17 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
SchemaConfigError,
TestConfigError,
ParsingError,
PropertyYMLInvalidTagError,
PropertyYMLMissingVersionError,
PropertyYMLVersionNotIntError,
DbtValidationError,
YamlLoadError,
YamlParseDictError,
Expand Down Expand Up @@ -575,20 +572,6 @@ def parse_file(self, block: FileBlock, dct: Dict = None) -> None:
group_parser.parse()


def check_format_version(file_path, yaml_dct) -> None:
if "version" not in yaml_dct:
raise PropertyYMLMissingVersionError(file_path)

version = yaml_dct["version"]
# if it's not an integer, the version is malformed, or not
# set. Either way, only 'version: 2' is supported.
if not isinstance(version, int):
raise PropertyYMLVersionNotIntError(file_path, version)

if version != 2:
raise PropertyYMLInvalidTagError(file_path, version)


Parsed = TypeVar("Parsed", UnpatchedSourceDefinition, ParsedNodePatch, ParsedMacroPatch)
NodeTarget = TypeVar("NodeTarget", UnparsedNodeUpdate, UnparsedAnalysisUpdate)
NonSourceTarget = TypeVar(
Expand Down
1 change: 0 additions & 1 deletion core/dbt/tests/fixtures/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def project_config_update():
@pytest.fixture(scope="class")
def dbt_project_yml(project_root, project_config_update, logs_dir):
project_config = {
"config-version": 2,
"name": "test",
"profile": "test",
"log-path": logs_dir,
Expand Down
11 changes: 1 addition & 10 deletions test/unit/test_contracts_project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from .utils import ContractTestCase

from dbt.dataclass_schema import ValidationError
Expand Down Expand Up @@ -35,13 +36,3 @@ def test_invalid_name(self):
}
with self.assertRaises(ValidationError):
self.ContractType.validate(dct)

def test_unsupported_version(self):
dct = {
'name': 'test',
'version': '1.0',
'profile': 'test',
'project-root': '/usr/src/app',
}
with self.assertRaises(Exception):
self.ContractType.from_dict(dct)
33 changes: 33 additions & 0 deletions tests/functional/basic/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@
from dbt.exceptions import ProjectContractError


simple_model_sql = """
select true as my_column
"""

simple_model_yml = """
models:
- name: simple_model
description: "is sythentic data ok? my column:"
columns:
- name: my_column
description: asked and answered
"""


class TestSchemaYmlVersionMissing:
@pytest.fixture(scope="class")
def models(self):
return {"simple_model.sql": simple_model_sql, "simple_model.yml": simple_model_yml}

def test_empty_version(self, project):
run_dbt(["run"], expect_pass=True)


class TestProjectConfigVersionMissing:
# default dbt_project.yml has config-version: 2
@pytest.fixture(scope="class")
def project_config_remove(self):
return ["config-version"]

def test_empty_version(self, project):
run_dbt(["run"], expect_pass=True)


class TestProjectYamlVersionMissing:
# default dbt_project.yml does not fill version

Expand Down

0 comments on commit 9090268

Please sign in to comment.