Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message for Private package definition #10084

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240502-154430.yaml
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 11 additions & 1 deletion core/dbt/contracts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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
Expand All @@ -92,7 +102,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
Expand Down
9 changes: 7 additions & 2 deletions core/dbt/deps/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
GitPackage,
LocalPackage,
PackageSpec,
PrivatePackage,
RegistryPackage,
TarballPackage,
)
Expand All @@ -16,7 +17,7 @@
from dbt.deps.registry import RegistryUnpinnedPackage
from dbt.deps.tarball import TarballUnpinnedPackage
from dbt.exceptions import (
DbtInternalError,
DependencyError,
DuplicateDependencyToRootError,
DuplicateProjectDependencyError,
MismatchedDependencyTypeError,
Expand Down Expand Up @@ -74,10 +75,14 @@
pkg = TarballUnpinnedPackage.from_contract(contract)
elif isinstance(contract, GitPackage):
pkg = GitUnpinnedPackage.from_contract(contract)
elif isinstance(contract, PrivatePackage):
raise DependencyError(
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:
raise DbtInternalError("Invalid package type {}".format(type(contract)))
raise DependencyError("Invalid package type {}".format(type(contract)))

Check warning on line 85 in core/dbt/deps/resolver.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/deps/resolver.py#L85

Added line #L85 was not covered by tests
self.incorporate(pkg)

@classmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from dbt.exceptions import ConfigUpdateError
from dbt.tests.util import get_manifest, run_dbt
from dbt_common.dataclass_schema import ValidationError

Expand Down Expand Up @@ -304,7 +305,7 @@ def test__invalid_color_config_block(
self,
project,
):
with pytest.raises(ValidationError):
with pytest.raises((ValidationError, ConfigUpdateError)):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused an issue in CI because of the execution order of tests. Since Gerda also ran into this before, I am just fixing it here.

run_dbt(["compile"])


Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,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.DependencyError, "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(
{
Expand Down