From 67d8ce398f89b10abf5ac86336d33252a062510d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:07:13 -0800 Subject: [PATCH] [Backport 1.7.latest] Fix dbt deps failing on tarballs (#9075) --- .../unreleased/Fixes-20231113-114956.yaml | 6 +++ core/dbt/deps/tarball.py | 3 +- .../dependencies/test_simple_dependency.py | 41 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Fixes-20231113-114956.yaml diff --git a/.changes/unreleased/Fixes-20231113-114956.yaml b/.changes/unreleased/Fixes-20231113-114956.yaml new file mode 100644 index 00000000000..77bb210002c --- /dev/null +++ b/.changes/unreleased/Fixes-20231113-114956.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix formatting of tarball information in packages-lock.yml +time: 2023-11-13T11:49:56.437007-08:00 +custom: + Author: ChenyuLInx QMalcolm + Issue: "9062" diff --git a/core/dbt/deps/tarball.py b/core/dbt/deps/tarball.py index 09462158dbe..5be17446b96 100644 --- a/core/dbt/deps/tarball.py +++ b/core/dbt/deps/tarball.py @@ -31,8 +31,7 @@ def name(self): def to_dict(self) -> Dict[str, str]: return { "tarball": self.tarball, - "version": self.version, - "package": self.package, + "name": self.package, } def get_version(self): diff --git a/tests/functional/dependencies/test_simple_dependency.py b/tests/functional/dependencies/test_simple_dependency.py index b8c17cfc0e6..a796c694211 100644 --- a/tests/functional/dependencies/test_simple_dependency.py +++ b/tests/functional/dependencies/test_simple_dependency.py @@ -4,9 +4,11 @@ from pathlib import Path +from dbt.exceptions import DbtProjectError from dbt.tests.util import ( check_relations_equal, run_dbt, + write_config_file, ) @@ -374,3 +376,42 @@ def test_deps_bad_profile(self, project): del os.environ["PROFILE_TEST_HOST"] run_dbt(["deps"]) run_dbt(["clean"]) + + +class TestSimpleDependcyTarball(object): + @pytest.fixture(scope="class") + def packages(self): + return { + "packages": [ + { + "tarball": "https://codeload.github.com/dbt-labs/dbt-utils/tar.gz/0.9.6", + "name": "dbt_utils", + } + ] + } + + def test_deps_simple_tarball_doesnt_error_out(self, project): + run_dbt(["deps"]) + assert len(os.listdir("dbt_packages")) == 1 + + +class TestBadTarballDependency(object): + def test_malformed_tarball_package_causes_exception(self, project): + # We have to specify the bad formatted package here because if we do it + # in a `packages` fixture, the test will blow up in the setup phase, meaning + # we can't appropriately catch it with a `pytest.raises` + bad_tarball_package_spec = { + "packages": [ + { + "tarball": "https://codeload.github.com/dbt-labs/dbt-utils/tar.gz/0.9.6", + "version": "dbt_utils", + } + ] + } + write_config_file(bad_tarball_package_spec, "packages.yml") + + with pytest.raises( + DbtProjectError, match=r"The packages.yml file in this project is malformed" + ) as e: + run_dbt(["deps"]) + assert e is not None