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

Set the default value of -check_direct_dependencies to error #21797

Conversation

shinypb
Copy link

@shinypb shinypb commented Mar 25, 2024

What

Change the default value of --check_direct_dependencies from "warning" to "error":

--check_direct_dependencies = <off, warning or error> default: "warning"
Check if the direct bazel_dep dependencies declared in the root module are the same versions you get in the resolved dependency graph. Valid values are off to disable the check, warning to print a warning when mismatch detected or error to escalate it to a resolution failure.

Why

This feature has the potential to protect users from unexpected package upgrades and the unintended side effects that they can bring along, but it's not doing as much good as it can be by being a warning rather than an error. This is the sort of thing you don't know you need until it's already bitten you—setting it to an error will give people protection by default, and it's easy for them to opt out into a less safe mode of operation if they need to.

Here's the exact situation that I encountered last week:

  • my project uses rules_python 0.26.0
  • I pulled in a new dependency, rules_multirun, which happens to use rules_python 0.27.1
  • this had the unintended side effect of upgrading my project to rules_python 0.27.1, which broke some of our internal tooling and was unfortunately not caught prior to deployment

This was arguably my fault: a warning was emitted, but I didn't happen to notice it in time. Even once I did see it, it was not clear what what had introduced the issue—the message doesn't explain why the resolved dependency graph didn't match the root module:

WARNING: For repository 'rules_python', the root module requires module version rules_python@0.26.0, but got rules_python@0.27.1 in the resolved dependency graph.

The good news is that --check_direct_dependencies=error already exists and solves this problem completely; when set, we get an error instead:

ERROR: For repository 'rules_python', the root module requires module version rules_python@0.26.0, but got rules_python@0.27.1 in the resolved dependency graph.

If this had been an error, the source of the discrepancy would've been immediately obvious. Unless there are other implications to this change, I believe that changing the default value to error makes a lot of sense and would make Bazel safer and easier to operate, particularly in larger repositories with many dependencies and many contributors, not all of whom are necessarily Bazel experts.

See also

Issue #21794 (reported by me; included for completeness)
Slack conversation

Copy link

google-cla bot commented Mar 25, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@shinypb shinypb changed the title Set the default value of -check_direct_dependencies to error, rather … Set the default value of -check_direct_dependencies to error Mar 25, 2024
@meteorcloudy meteorcloudy self-requested a review March 26, 2024 16:24
@meteorcloudy meteorcloudy added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. area-Bzlmod Bzlmod-specific PRs, issues, and feature requests labels Mar 26, 2024
@sgowroji sgowroji added the awaiting-user-response Awaiting a response from the author label Mar 28, 2024
@shinypb shinypb marked this pull request as ready for review April 23, 2024 19:57
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Apr 23, 2024
@shinypb shinypb force-pushed the check_direct_dependencies_default_to_error branch from 7ec5d5c to 0894f19 Compare April 23, 2024 20:00
@shinypb shinypb closed this May 10, 2024
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests awaiting-user-response Awaiting a response from the author team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants