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

don't attempt to update a package if no versions could be found #8502

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

brettfo
Copy link
Collaborator

@brettfo brettfo commented Dec 1, 2023

This partially fixes the issue:

ERROR undefined method `fetch' for nil:NilClass

           latest_version: preferred_resolvable_version_details.fetch(:version)&.to_s,
                                                               ^^^^^^

This can happen if querying NuGet for the available package versions returns an empty set and can happen if the package source doesn't contain that package.

The fix is to only report dependencies where at least one of the package repositories reported at least one search result.

@brettfo brettfo requested a review from a team as a code owner December 1, 2023 01:02
@github-actions github-actions bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label Dec 1, 2023
@deivid-rodriguez
Copy link
Contributor

As you explained, this is more of a "could not find any versions for this package in the remote source" situation, rather than a "this package is update to date" situation, which is the effect of early returning true here.

Like in 38d5044, I'd rather raise an explicit, but unexpected, error that explains the situation and makes it easier to figure out the real culprit.

My understanding is that if you had introduced this code from the beginning, it would've been really hard to notice this bug. Maybe in this case it's not a very bad bug (you just have a "phantom dependency" around that dependabot thinks it's valid and up to date), but I'd rather be sure that the update checker is never fed with dependencies that don't really exist, and I believe failing hard is an easy way to achieve that.

@brettfo brettfo force-pushed the dev/brettfo/no-package-versions-found branch from f5b046d to 72c721b Compare December 1, 2023 23:57
@brettfo brettfo force-pushed the dev/brettfo/no-package-versions-found branch 3 times, most recently from defe51a to 8268aa4 Compare December 4, 2023 21:40
@brettfo
Copy link
Collaborator Author

brettfo commented Dec 4, 2023

@deivid-rodriguez I re-worked this change to only report a Dependency if one of the package sources actually contains that package. Since this moves a bunch of network calls into the file parser tests, the bulk of this PR is simply stubbing the search requests.

Copy link
Collaborator

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

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

Looks good. If RepositoryFinder understood nuget.configs <packageSourceMapping>, it could potentially reduce the number of dependeny urls that had to be checked. Future enhancement maybe.

@brettfo
Copy link
Collaborator Author

brettfo commented Dec 4, 2023

Looks good. If RepositoryFinder understood nuget.configs , it could potentially reduce the number of dependeny urls that had to be checked. Future enhancement maybe.

Good call, that'll improve the other lookups, too. I'm going to add one or 2 more test scenarios, just to be safe, then I think this is ready for final approval.

This will prevent reporting a dependency that doesn't exist on any of the repos and therefore can't be updated.
@brettfo brettfo force-pushed the dev/brettfo/no-package-versions-found branch from 8268aa4 to f3548ca Compare December 4, 2023 22:57
@brettfo
Copy link
Collaborator Author

brettfo commented Dec 4, 2023

Updated to stub out more network calls instead of pulling from a file. Reduced changed lines from 36k to 300.

@brettfo brettfo force-pushed the dev/brettfo/no-package-versions-found branch from d29b3aa to 26f1b0a Compare December 5, 2023 02:08
name: name,
version: version,
package_manager: "nuget",
requirements: [requirement]
)

# only include dependency if one of the sources has it
return unless dependency_has_search_results?(dependency)
Copy link
Member

Choose a reason for hiding this comment

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

Consider logging the dependency and why it was skipped. It might be hard to track down why a certain dependency is missing without a log message here.

Copy link
Member

@jakecoffman jakecoffman left a comment

Choose a reason for hiding this comment

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

This is a bit different than how most of the other ecosystems do it, but let's give it a shot. I like that the calls are cached so they don't have to be made again during the UpdateChecker step.

@jakecoffman
Copy link
Member

I deployed this and a new exception popped up:

updater | 2023/12/05 13:01:59 ERROR key not found: :search_url
updater | 2023/12/05 13:01:59 ERROR /home/dependabot/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb:308:in `fetch'
updater | 2023/12/05 13:01:59 ERROR /home/dependabot/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb:308:in `execute_search_for_dependency_url'
updater | 2023/12/05 13:01:59 ERROR /home/dependabot/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb:293:in `block in dependency_has_search_results?'

Reproducible with: dependabot update nuget udap-tools/udap-dotnet

@jakecoffman
Copy link
Member

Over the last 3 hours the NilClass error has dropped dramatically. Now the KeyError is frequent, but it's an order of magnitude less than the NilClass error was. This is definitely an improvement, I'll go ahead and merge this so we can keep moving forward.

@jakecoffman jakecoffman merged commit 7b3b9b1 into main Dec 5, 2023
115 checks passed
@jakecoffman jakecoffman deleted the dev/brettfo/no-package-versions-found branch December 5, 2023 15:30
@brettfo
Copy link
Collaborator Author

brettfo commented Dec 5, 2023

@jakecoffman PR for key not found: :search_url here: #8534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: dotnet:nuget NuGet packages via nuget or dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants