[Refactor] Review comments from #12902
- Dominant language
- Rust
- Stars
- 13.8k
- Forks
- 2.6k
- Avg merge
- 21h 31m
- Merged PRs (30d)
- 56
Description
### Housekeeping
- [x] I am a maintainer of dbt-core
### Short description
[Copilot AI had a few code suggestions](https://github.com/dbt-labs/dbt-core/pull/12902#pullrequestreview-4245672637) while reviewing https://github.com/dbt-labs/dbt-core/pull/12902.
The code was lifted-and-shifted, so we intentionally wanted to keep it as-is rather than make any changes. This issue is to review those suggestions and adopt any that make sense.
---
[`core/dbt/deps/private_package.py`](https://github.com/dbt-labs/dbt-core/pull/12902/files/15470c0de1fc2c8d8025392a1af07b7748e0d8c4#diff-dd3069c35e5cdcd2327ef867845b8ec3f966d617e2259148484471289181ba59)
`GitProvider` overrides `__eq__` to make ADO variants equal, but keeps the default `Enum`/`StrEnum` hashing semantics. This violates the Python hash/eq contract (e.g., `GitProvider.ADO == GitProvider.AZURE_DEVOPS` but they will not behave as the same key in dicts/sets). Consider avoiding custom `__eq__` (use a normalization/matching helper instead) or implement a compatible `__hash__` based on the normalized provider value.
---
Comment on line R115
https://github.com/dbt-labs/dbt-core/pull/12902/changes#r3202933839
`PrivatePackageName._parts` will raise a `ValueError` if the input does not contain at least `org/repo` (e.g. missing `/`). Since `PackageConfig.validate` does not validate `private` values, this will surface as an unhandled exception. Recommend validating the format here (or in contract validation) and raising a `PrivatePackageResolutionError` with a clear message.
`core/dbt/deps/private_package.py`
```
head, *groups, tail = self.split("/")
--
parts = self.split("/")
if len(parts) < 2 or not parts[0] or not parts[-1]:
raise PrivatePackageResolutionError(
f"Invalid private package name '{self}'. Expected format 'org/repo' or "
"'org/group/.../repo'."
)
head, *groups, tail = parts
```
---
Comment on lines R360 to R366
https://github.com/dbt-labs/dbt-core/pull/12902/changes#r3202933959
For the `ado`/`azure_devops` SSH fallback, the Azure DevOps SSH URL format is `org/project/repo` (exactly 3 path segments). The current check only enforces a minimum of 3 parts, so inputs like `org/a/b/repo` will produce an invalid SSH URL without an error. Consider validating the part count is exactly 3 for these providers and raising a clear `PrivatePackageResolutionError` otherwise.
---
Comment on lines R383 to R388
https://github.com/dbt-labs/dbt-core/pull/12902/changes#r3202933896
`PrivatePinnedPackage.to_dict()` drops the `provider` field entirely. Since `package-lock.yml` is used as the source of truth on subsequent `dbt deps` runs, omitting `provider` means a locked private dependency can be re-resolved with `provider=None` (defaulting to GitHub SSH) and break installs for GitLab/Azure DevOps packages. The lock file should persist `provider` (when set) so re-installs are reproducible.
---
Comment on lines R413 to R425
https://github.com/dbt-labs/dbt-core/pull/12902/changes#r3202933925
`PrivateUnpinnedPackage.from_contract()` sets `git_unrendered=contract.private` and does not retain `contract.provider`. For consistency with `GitUnpinnedPackage.from_contract`, this should use the unrendered value (if present) and carry `provider` through to the pinned/lock representation; otherwise secrets/templating and provider-specific SSH fallback behavior can be lost when creating/using `package-lock.yml`.
---
Comment on lines R50 to R61
https://github.com/dbt-labs/dbt-core/pull/12902/changes#r3202934002
This test asserts the entire `package-lock.yml` contents including an exact commit SHA (`revision`) and `sha1_hash`. That makes the test brittle if the upstream repo/tag ever moves (or if lockfile formatting/hash inputs change). Consider parsing the YAML and asserting the important invariants instead (single package entry, `private` value, `revision` looks like a 40-char SHA, no token leakage) without hard-coding the exact SHA/hash.
---
https://github.com/dbt-labs/dbt-core/pull/12902#pullrequestreview-4293253945
[core/dbt/deps/private_package.py](https://github.com/dbt-labs/dbt-core/pull/12902/files/4c895780ef46bfb17f717a3f04dfdba73beb602b#diff-dd3069c35e5cdcd2327ef867845b8ec3f966d617e2259148484471289181ba59)
Comment on lines +170 to +193
[codescene-delta-analysis](https://github.com/apps/codescene-delta-analysis) Bot
[4 days ago](https://github.com/dbt-labs/dbt-core/pull/12902#discussion_r3244135456)
❌ New issue: [Complex Method](https://codescene.io/projects/43783/delta?repo-id=159897&review-id=12902&biomarker=Complex+Method&filename=core%2Fdbt%2Fdeps%2Fprivate_package.py&method=build)
build has a cyclomatic complexity of 9, threshold = 9
---
https://github.com/dbt-labs/dbt-core/pull/12902#pullrequestreview-4293253945
[core/dbt/deps/private_package.py](https://github.com/dbt-labs/dbt-core/pull/12902/files/4c895780ef46bfb17f717a3f04dfdba73beb602b#diff-dd3069c35e5cdcd2327ef867845b8ec3f966d617e2259148484471289181ba59)
Comment on lines +384 to +396
[codescene-delta-analysis](https://github.com/apps/codescene-delta-analysis) Bot
[4 days ago](https://github.com/dbt-labs/dbt-core/pull/12902#discussion_r3244135490)
❌ New issue: [Excess Number of Function Arguments](https://codescene.io/projects/43783/delta?repo-id=159897&review-id=12902&biomarker=Excess+Number+of+Function+Arguments&filename=core%2Fdbt%2Fdeps%2Fprivate_package.py&method=PrivatePinnedPackage.__init__)
PrivatePinnedPackage.init has 6 arguments, max arguments = 4
---
https://github.com/dbt-labs/dbt-core/pull/12902#pullrequestreview-4293253945
[core/dbt/deps/private_package.py](https://github.com/dbt-labs/dbt-core/pull/12902/files/4c895780ef46bfb17f717a3f04dfdba73beb602b#diff-dd3069c35e5cdcd2327ef867845b8ec3f966d617e2259148484471289181ba59)
Comment on lines +407 to +417
[codescene-delta-analysis](https://github.com/apps/codescene-delta-analysis) Bot
[4 days ago](https://github.com/dbt-labs/dbt-core/pull/12902#discussion_r3244135516)
❌ New issue: [Excess Number of Function Arguments](https://codescene.io/projects/43783/delta?repo-id=159897&review-id=12902&biomarker=Excess+Number+of+Function+Arguments&filename=core%2Fdbt%2Fdeps%2Fprivate_package.py&method=PrivateUnpinnedPackage.__init__)
PrivateUnpinnedPackage.init has 6 arguments, max arguments = 4
---
https://github.com/dbt-labs/dbt-core/pull/12902#pullrequestreview-4293253945
[tests/unit/deps/test_private_package.py](https://github.com/dbt-labs/dbt-core/pull/12902/files/4c895780ef46bfb17f717a3f04dfdba73beb602b#diff-44e134fd82bcc58ed2cbbb9344ec8285188ca7fc93b998549d04635fb6aafb3c)
[codescene-delta-analysis](https://github.com/apps/codescene-delta-analysis) Bot
[4 days ago](https://github.com/dbt-labs/dbt-core/pull/12902#discussion_r3244135544)
❌ New issue: [Lines of Code in a Single File](https://codescene.io/projects/43783/delta?repo-id=159897&review-id=12902&biomarker=Lines+of+Code+in+a+Single+File&filename=tests%2Funit%2Fdeps%2Ftest_private_package.py&method=)
This module has 927 lines of code, improve code health by reducing it to 600
---
https://github.com/dbt-labs/dbt-core/pull/12902#pullrequestreview-4293253945
[tests/unit/deps/test_private_package.py](https://github.com/dbt-labs/dbt-core/pull/12902/files/4c895780ef46bfb17f717a3f04dfdba73beb602b#diff-44e134fd82bcc58ed2cbbb9344ec8285188ca7fc93b998549d04635fb6aafb3c)
[codescene-delta-analysis](https://github.com/apps/codescene-delta-analysis) Bot
[4 days ago](https://github.com/dbt-labs/dbt-core/pull/12902#discussion_r3244135561)
❌ New issue: [Low Cohesion](https://codescene.io/projects/43783/delta?repo-id=159897&review-id=12902&biomarker=Low+Cohesion&filename=tests%2Funit%2Fdeps%2Ftest_private_package.py&method=)
This module has at least 28 different responsibilities amongst its 75 functions, threshold = 4
---
[tests/unit/deps/test_private_package.py](https://github.com/dbt-labs/dbt-core/pull/12902/files/4c895780ef46bfb17f717a3f04dfdba73beb602b#diff-44e134fd82bcc58ed2cbbb9344ec8285188ca7fc93b998549d04635fb6aafb3c)
Comment on lines +39 to +48
[codescene-delta-analysis](https://github.com/apps/codescene-delta-analysis) Bot
[4 days ago](https://github.com/dbt-labs/dbt-core/pull/12902#discussion_r3244135594)
❌ New issue: [Code Duplication](https://codescene.io/projects/43783/delta?repo-id=159897&review-id=12902&biomarker=Code+Duplication&filename=tests%2Funit%2Fdeps%2Ftest_private_package.py&method=)
The module contains 16 functions with similar structure: TestADOWildcardProjectResolution.test_use_case_C3,TestADOWildcardProjectResolution.test_use_case_C6,TestADOWildcardProjectResolution.test_use_case_C7,TestAzurePrivatePackageResolution.test_use_case_A1 and 12 more functions
---
[tests/unit/deps/test_private_package.py](https://github.com/dbt-labs/dbt-core/pull/12902/files/4c895780ef46bfb17f717a3f04dfdba73beb602b#diff-44e134fd82bcc58ed2cbbb9344ec8285188ca7fc93b998549d04635fb6aafb3c)
Comment on lines +121 to +153
[codescene-delta-analysis](https://github.com/apps/codescene-delta-analysis) Bot
[4 days ago](https://github.com/dbt-labs/dbt-core/pull/12902#discussion_r3244135630)
❌ New issue: [Excess Number of Function Arguments](https://codescene.io/projects/43783/delta?repo-id=159897&review-id=12902&biomarker=Excess+Number+of+Function+Arguments&filename=tests%2Funit%2Fdeps%2Ftest_private_package.py&method=git_repositories_multi_provider)
git_repositories_multi_provider has 5 arguments, max arguments = 4
---
`core/dbt/deps/private_package.py`
Comment on lines R393 to R404
In `_get_ssh_fallback_url`, the ADO/azure_devops validation only checks `len(private_def.split('/')) < 3`, which allows 4+ path segments even though the error message and tests describe a strict `org/project/repo` (3-part) format. This can generate invalid ADO SSH URLs for inputs like `org/project/repo/extra`. Consider enforcing exactly 3 parts (and optionally trimming whitespace) so the constructed URL is always valid.
---
`core/dbt/deps/private_package.py`
Comment on lines R475 to R479
`PrivateUnpinnedPackage.incorporate()` currently hard-codes `provider=self.provider` and ignores `other.provider`. If duplicate private packages are incorporated (PackageListing.incorporate), this can silently drop an explicitly-specified provider from the later entry, or hide a provider mismatch. Consider either: (a) preserving the non-None provider when either side specifies one, and raising if both are set but differ; or (b) explicitly validating they match before merging.
---
### Acceptance criteria
1. Understand each review comment by Copilot AI.
2. Adopt those that make sense; dismiss those that don't
### Suggested Tests
N/A
### Impact to Other Teams
N/A
### Will backports be required?
N/A
### Context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.