Skip to content

Fix Bundler crashing when installing very old gems:#9401

Merged
hsbt merged 1 commit intoruby:masterfrom
Shopify:ec-version-requirements
Mar 17, 2026
Merged

Fix Bundler crashing when installing very old gems:#9401
hsbt merged 1 commit intoruby:masterfrom
Shopify:ec-version-requirements

Conversation

@Edouard-chin
Copy link
Collaborator

@Edouard-chin Edouard-chin commented Mar 16, 2026

What was the end-user or developer problem that led to this PR?

There is a regression where bundler can no longer install gems that were packaged a long time ago, like the memoize gem.

Bundler will crash with such error:

Installing memoize 1.3.1
--- ERROR REPORT TEMPLATE -------------------------------------------------------

NoMethodError: undefined method 'as_list' for nil /Users/edouard/src/opensource/rubygems/lib/rubygems/dependency.rb:146:in 'Gem::Dependency#requirements_list'

What is your fix for the problem, implemented in this PR?

Context

These very old gems were packaged at the time were a Gem::Dependency had no ivars requirement. This is what the dumped gemspec looks like:

dependencies: 
- !ruby/object:Gem::Dependency 
  name: test-unit
  type: :development
  version_requirement: 
  version_requirements: !ruby/object:Gem::Requirement 
    requirements: 
    - - ">="
      - !ruby/object:Gem::Version 
        version: 2.0.2
    version: 

As opposed to a gem that was packaged more recently:

- !ruby/object:Gem::Dependency
  name: minitest-global_expectations
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: '0'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: '0'

The change we made in cbe57bb#diff-5ccc8aa468df013cc970580e88642417da12284da6529a4885b9abf447ae95edL529 broke old gem installation.

Solution

If requirement isn't set in the hash, look for version_requirements instead.

Make sure the following tasks are checked

cc/ @hsbt Let me know if this fix is acceptable

- ### Problem

  There is a regression where bundler can longer install gems that
  were packaged a long time ago, like the [memoize gem](https://rubygems.org/gems/memoize).

  Bundler will crash with such error:

  ```
  Installing memoize 1.3.1
  --- ERROR REPORT TEMPLATE -------------------------------------------------------

  NoMethodError: undefined method 'as_list' for nil
  /Users/edouard/src/opensource/rubygems/lib/rubygems/dependency.rb:146:in 'Gem::Dependency#requirements_list'
  ```

  ### Context

  These very old gems were packaged at the time were a
  `Gem::Dependency` had no ivars `requirement`.
  This is what the dumped gemspec looks like:

  ```
  dependencies:
  - !ruby/object:Gem::Dependency
  name: test-unit
  type: :development
  version_requirement:
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: 2.0.2
    version:
  ```

  As opposed to a gem that was packaged more recently:

  ```
  - !ruby/object:Gem::Dependency
  name: minitest-global_expectations
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: '0'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: '0'
  ```

  The change we made in ruby@cbe57bb#diff-5ccc8aa468df013cc970580e88642417da12284da6529a4885b9abf447ae95edL529
  broke old gem installation.

  ### Solution

  If `requirement` isn't set in the hash, look for
  `version_requirements` instead.
@hsbt
Copy link
Member

hsbt commented Mar 17, 2026

🙏 Thanks!

Is this gem being used in application on Shopify? Currently, I'm testing based on download numbers, but we're looking for a more effective way to find it.

@hsbt hsbt merged commit 5dbc50d into ruby:master Mar 17, 2026
110 of 112 checks passed
@Edouard-chin
Copy link
Collaborator Author

Edouard-chin commented Mar 17, 2026

Is this gem being used in application on Shopify?

Nop, it's not. It's used in my benchmarks only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants