Skip to content

Commit

Permalink
add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-connors-3 committed Jul 7, 2023
1 parent dda77f7 commit e4e80f9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dbt_meshify/storage/yaml_editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ def get_latest_yml_defined_version(self, model_yml: Dict[str, Any]):
if no versions, returns 0
"""
model_yml_versions = model_yml.get("versions", [])
return max([v.get("v") for v in model_yml_versions]) if model_yml_versions else 0
try:
return max([int(v.get("v")) for v in model_yml_versions]) if model_yml_versions else 0
except ValueError:
raise ValueError(
f"Version not an integer, can't increment version for {model_yml.get('name')}"
)

def add_model_version_to_yml(
self,
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,12 @@
- v: 2
defined_in: daves_model
"""

model_yml_string_version = """
models:
- name: shared_model
latest_version: john_olerud
description: "this is a test model"
versions:
- v: john_olerud
"""
34 changes: 34 additions & 0 deletions tests/integration/test_version_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
expected_versioned_model_yml_no_yml,
model_yml_increment_version,
model_yml_no_col_no_version,
model_yml_string_version,
shared_model_sql,
)

Expand Down Expand Up @@ -119,3 +120,36 @@ def test_add_version_to_yml(start_yml, end_yml, start_files, expected_files, com
yml_file.unlink()
reset_model_files(["shared_model.sql"])
assert actual == yaml.safe_load(end_yml)


@pytest.mark.parametrize(
"start_yml,start_files,command_options",
[
(
model_yml_string_version,
["shared_model.sql"],
[],
),
],
ids=["1"],
)
def test_add_version_to_invalid_yml(start_yml, start_files, command_options):
yml_file = proj_path / "models" / "_models.yml"
reset_model_files(start_files)
yml_file.parent.mkdir(parents=True, exist_ok=True)
runner = CliRunner()
# only create file if start_yml is not None
# in situations where models don't have a patch path, there isn't a yml file to read from
if start_yml:
yml_file.touch()
start_yml_content = yaml.safe_load(start_yml)
with open(yml_file, "w+") as f:
yaml.safe_dump(start_yml_content, f, sort_keys=False)
base_command = ["--select", "shared_model", "--project-path", proj_path_string]
base_command.extend(command_options)
result = runner.invoke(add_version, base_command, catch_exceptions=True)
assert result.exit_code == 1
assert "Version not an integer" in str(result.exception)
# reset the read path to the default in the logic
yml_file.unlink()
reset_model_files(["shared_model.sql"])

0 comments on commit e4e80f9

Please sign in to comment.