From 9308d164ed7837712de915f5ca7c6d97a991f5cc Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Thu, 2 May 2024 15:45:13 -0700 Subject: [PATCH] nits --- .../unreleased/Under the Hood-20240502-154430.yaml | 6 ++++++ core/dbt/contracts/project.py | 12 +++++++++++- core/dbt/deps/resolver.py | 5 +++++ tests/unit/test_deps.py | 13 +++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Under the Hood-20240502-154430.yaml diff --git a/.changes/unreleased/Under the Hood-20240502-154430.yaml b/.changes/unreleased/Under the Hood-20240502-154430.yaml new file mode 100644 index 00000000000..6c17df3a6c6 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240502-154430.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Clear error message for Private package in dbt-core +time: 2024-05-02T15:44:30.713097-07:00 +custom: + Author: ChenyuLInx + Issue: "10083" diff --git a/core/dbt/contracts/project.py b/core/dbt/contracts/project.py index c2090eb4d10..8e1722247d2 100644 --- a/core/dbt/contracts/project.py +++ b/core/dbt/contracts/project.py @@ -77,6 +77,16 @@ def get_revisions(self) -> List[str]: return [str(self.revision)] +@dataclass +class PrivatePackage(Package): + private: str + provider: Optional[str] = None + revision: Optional[RawVersion] = None + warn_unpinned: Optional[bool] = field(default=None, metadata={"alias": "warn-unpinned"}) + subdirectory: Optional[str] = None + unrendered: Dict[str, Any] = field(default_factory=dict) + + @dataclass class RegistryPackage(Package): package: str @@ -91,7 +101,7 @@ def get_versions(self) -> List[str]: return [str(self.version)] -PackageSpec = Union[LocalPackage, TarballPackage, GitPackage, RegistryPackage] +PackageSpec = Union[LocalPackage, TarballPackage, GitPackage, RegistryPackage, PrivatePackage] @dataclass diff --git a/core/dbt/deps/resolver.py b/core/dbt/deps/resolver.py index 5f890109b0e..3e183b69177 100644 --- a/core/dbt/deps/resolver.py +++ b/core/dbt/deps/resolver.py @@ -21,6 +21,7 @@ LocalPackage, TarballPackage, GitPackage, + PrivatePackage, RegistryPackage, ) @@ -76,6 +77,10 @@ def update_from(self, src: List[PackageSpec]) -> None: pkg = TarballUnpinnedPackage.from_contract(contract) elif isinstance(contract, GitPackage): pkg = GitUnpinnedPackage.from_contract(contract) + elif isinstance(contract, PrivatePackage): + raise DbtInternalError( + f'Cannot resolve private package {contract.private} because git provider integration is missing. Please use a "git" package instead.' + ) elif isinstance(contract, RegistryPackage): pkg = RegistryUnpinnedPackage.from_contract(contract) else: diff --git a/tests/unit/test_deps.py b/tests/unit/test_deps.py index d4edd90b134..b77952e5ab1 100644 --- a/tests/unit/test_deps.py +++ b/tests/unit/test_deps.py @@ -792,6 +792,19 @@ def test_dependency_resolution(self): self.assertEqual(resolved[1].name, "dbt-labs-test/b") self.assertEqual(resolved[1].version, "0.2.1") + def test_private_package_raise_error(self): + package_config = PackageConfig.from_dict( + { + "packages": [ + {"private": "dbt-labs-test/a", "subdirectory": "foo-bar"}, + ], + } + ) + with self.assertRaisesRegex( + dbt.exceptions.DbtInternalError, "Cannot resolve private package" + ): + resolve_packages(package_config.packages, mock.MagicMock(project_name="test"), {}) + def test_dependency_resolution_allow_prerelease(self): package_config = PackageConfig.from_dict( {