`clear_sources` is not honoured when listing available versions from remote
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.5k
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 23
Description
Description
When using a constraint (like ~> 1.0) if a newer gem exists in the default source (e.g. 1.5), but not the source provided in chef_gem (e.g. 1.1) it will try to install the "latest" version (e.g 1.5) against the source in chef_gem resulting in a failure. This occurs even if the following are set:
clear_sources trueinclude_default_source false
It appears that --clear-sources is not passed to candidate_version_from_remote, but it is in install_via_gem_command. This explains why it's not just installing the latest version from the default source, but a mix.
I am not familiar with the codebase, however I've tried to provide a simple fix in: https://github.com/chef/chef/pull/16267
Chef Version
18.11.11
Platform Version
Ubuntu 24.04
Replication Case
Default source is rubygems.org. Use a resource like this:
chef_gem 'cool-gem' do
action :install
clear_sources true
include_default_source false
source 'https://cool-rubygems.example.com'
version '~> 1.0'
end
If rubygems.org has 1.5 and cool-rubygems.example.com only has up to 1.2, then the above resource will try to install 1.5 from cool-rubygems.example.com, which fails.
Client Output
I can provide sanitised logs if my investigation is incorrect.
Stacktrace
I can provide a sanitised stacktrace if my investigation is incorrect.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/chef/provider/package/rubygems.rb around candidate_version_from_remote and install_via_gem_command, as identified in the issue. Review pull request #16267 and verify the replication case: with clear_sources and include_default_source false, remote version selection should not use versions available only from the default source.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100