Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Fix resolver incorrectly filtering gems by development self-dependencies - #9346

Closed
sferik wants to merge 1 commit into
ruby:masterfrom
sferik:fix_9319
Closed

sferik wants to merge 1 commit into
ruby:masterfrom
sferik:fix_9319

Conversation

@sferik

@sferik sferik commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

filter_invalid_self_dependencies used s.dependencies, which returns both runtime and development dependencies for locally-installed gems (StubSpecification), but only runtime dependencies for remote gems (EndpointSpecification). This inconsistency caused the resolver to silently drop valid gem versions.

In my case, minitest-bonus-assertions 3.0 has a development dependency on itself at ~> 2.0. Since 3.0 doesn't satisfy ~> 2.0, the filter removed it entirely, making bundle update fail with "Could not find gem" even though the version exists in the index.

The fix changes s.dependencies to s.runtime_dependencies, since development dependencies are irrelevant to resolution.

@hsbt

hsbt commented Mar 6, 2026

Copy link
Copy Markdown
Member

@sferik Thanks. In my understanding, the current behavior use standalone_migrations-1.0.13 in your test case?

`filter_invalid_self_dependencies` checked all dependencies, but should
only check runtime dependencies. Development self-dependencies are
irrelevant to resolution and should not disqualify a gem version.

Resolves ruby#9319.
@sferik

sferik commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

@hsbt No, standalone_migrations is not in this Gemfile or Gemfile.lock.

@simi

simi commented Mar 6, 2026 •

Copy link
Copy Markdown

That's IMHO invalid gem actually. What about to make specification policy warning about this (or even failure) so it is reported during build time it will result in broken gem and fix on gem side over band-aiding in RubyGems itself? What if the same would be in runtime dependencies, how the fix would work?

@kou

kou commented Mar 7, 2026

Copy link
Copy Markdown
Member

@sferik Could you report this to minitest-bonus-assertions?

BTW, why does minitest-bonus-assertions have itself as a development dependency...?

@sferik

sferik commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

I agree that this probably should’ve been rejected at built time, but it wasn’t—this gem made it into the wild and now is causing real issues. I can work on a rubygems patch to disallow self-dependencies in the future, but that doesn’t really solve my problem. I could try reporting this issue to minitest-bonus-assertions, but that project hasn’t been updated in 9 years.

I believe this patch would fix this issue and would also make the Bundler resolver marginally faster. Any reason not to accept it?

@simi

simi commented Mar 7, 2026 •

Copy link
Copy Markdown

I agree that this probably should’ve been rejected at built time, but it wasn’t—this gem made it into the wild and now is causing real issues. I can work on a rubygems patch to disallow self-dependencies in the future, but that doesn’t really solve my problem. I could try reporting this issue to minitest-bonus-assertions, but that project hasn’t been updated in 9 years.

I can provide the batch to be more strict in build time. Have you tried to contact the author of the gem? I have not found any try on tracker, so I tried on my own - halostatue/minitest-bonus-assertions#3. Sadly that happens from time to time that broken gem is published. I have tried to build the gem and it raises the warning already today. Would fixed release fix your original issue?

WARNING:  Self referencing dependency is unnecessary and strongly discouraged.
WARNING:  See https://guides.rubygems.org/specification-reference/ for help
  Successfully built RubyGem
  Name: minitest-bonus-assertions
  Version: 3.0
  File: minitest-bonus-assertions-3.0.gem

I believe this patch would fix this issue and would also make the Bundler resolver marginally faster. Any reason not to accept it?

It is bandaid. Everything works as intended, the gem is actually wrong. That's the reason.

@sferik sferik closed this Mar 7, 2026
Edouard-chin added a commit to Shopify/rubygems that referenced this pull request Mar 12, 2026
- ### Problem

  A gem that has a self-reference in its dependencies would previously
  get a warning during `gem build`, saying it's "discouradged".
  A gem that includes a self-reference can't be updated due to bundler
  filtering it out.

  https://github.com/ruby/rubygems/blob/6fd37f4afeb3943cf508d1394fcf4338a1266f2e/bundler/lib/bundler/resolver.rb#L405-L410

  I think we should be more strict and prevent the gem from building.

  ### Solution

  Raise an explicit error.

  This codepath is only hit when running `gem build`, so this change
  won't affect existing consumers of those gems (it was previously
  possible to install those gems, but not update them, see
  ruby#9346 for more context).
matzbot pushed a commit to ruby/ruby that referenced this pull request Mar 12, 2026
…ference:

- ### Problem

  A gem that has a self-reference in its dependencies would previously
  get a warning during `gem build`, saying it's "discouradged".
  A gem that includes a self-reference can't be updated due to bundler
  filtering it out.

  https://github.com/ruby/rubygems/blob/6fd37f4afeb3943cf508d1394fcf4338a1266f2e/bundler/lib/bundler/resolver.rb#L405-L410

  I think we should be more strict and prevent the gem from building.

  ### Solution

  Raise an explicit error.

  This codepath is only hit when running `gem build`, so this change
  won't affect existing consumers of those gems (it was previously
  possible to install those gems, but not update them, see
  ruby/rubygems#9346 for more context).

ruby/rubygems@fa4673953a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants