diff --git a/.changes/unreleased/Features-20230227-091316.yaml b/.changes/unreleased/Features-20230227-091316.yaml new file mode 100644 index 00000000000..264c7960216 --- /dev/null +++ b/.changes/unreleased/Features-20230227-091316.yaml @@ -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" diff --git a/core/dbt/config/project.py b/core/dbt/config/project.py index 8fc115e3820..f0d3d94e3f6 100644 --- a/core/dbt/config/project.py +++ b/core/dbt/config/project.py @@ -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( diff --git a/core/dbt/contracts/project.py b/core/dbt/contracts/project.py index 3041b1bd4b9..18c6a0ba758 100644 --- a/core/dbt/contracts/project.py +++ b/core/dbt/contracts/project.py @@ -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 diff --git a/core/dbt/exceptions.py b/core/dbt/exceptions.py index 297aa155a5e..4159b17d4be 100644 --- a/core/dbt/exceptions.py +++ b/core/dbt/exceptions.py @@ -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 diff --git a/core/dbt/parser/read_files.py b/core/dbt/parser/read_files.py index 92a91070594..3dc2c0fe44c 100644 --- a/core/dbt/parser/read_files.py +++ b/core/dbt/parser/read_files.py @@ -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 @@ -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): diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index 4e294e42846..b5ba2262c44 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -62,9 +62,6 @@ SchemaConfigError, TestConfigError, ParsingError, - PropertyYMLInvalidTagError, - PropertyYMLMissingVersionError, - PropertyYMLVersionNotIntError, DbtValidationError, YamlLoadError, YamlParseDictError, @@ -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( diff --git a/core/dbt/tests/fixtures/project.py b/core/dbt/tests/fixtures/project.py index 4bb9b81369a..bfdb4dfeab7 100644 --- a/core/dbt/tests/fixtures/project.py +++ b/core/dbt/tests/fixtures/project.py @@ -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, diff --git a/test/unit/test_contracts_project.py b/test/unit/test_contracts_project.py index c100eb24fcc..edb206ac202 100644 --- a/test/unit/test_contracts_project.py +++ b/test/unit/test_contracts_project.py @@ -1,3 +1,4 @@ + from .utils import ContractTestCase from dbt.dataclass_schema import ValidationError @@ -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) diff --git a/tests/functional/basic/test_project.py b/tests/functional/basic/test_project.py index 77f01c97b9f..10427c5ec3b 100644 --- a/tests/functional/basic/test_project.py +++ b/tests/functional/basic/test_project.py @@ -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