Project

General

Profile

Actions

Defect #44722

open

Bundler may fail with "You have already activated erb" when the adapter in database.yml uses ERB

Added by Go MAEDA 2 days ago. Updated 2 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Gems support
Resolution:
Affected version:

Description

When you run bundle install, Redmine's Gemfile reads config/database.yml to find which database adapters are used, and installs only the gems for those adapters. Because database.yml can contain ERB, the Gemfile runs require 'erb' and processes the file with ERB when an adapter: setting contains an ERB tag (since #41749), for example:

production:
  adapter: <%= ENV.fetch('DB_ADAPTER', 'postgresql') %>

However, require 'erb' loads the newest erb gem installed on the system. If that version is not the one in Gemfile.lock, Bundler stops with an error like this:

You have already activated erb 6.0.7, but your Gemfile requires erb 6.0.1.1. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

You can reproduce this by setting the adapter with ERB as in the example above, changing the erb version in Gemfile.lock to the default erb version of your Ruby (e.g. 6.0.1.1 for Ruby 4.0) while a newer erb is also installed, and then running bundle exec rails -v.

The attached patch runs ERB in a child Ruby process instead of loading it in the Gemfile. The child process processes the whole database.yml with ERB as before, so the result is the same, including ERB variables used across tags. The child process is started only when an adapter setting uses ERB, so other setups are not affected.


Files

Actions #1

Updated by Go MAEDA 2 days ago

  • Subject changed from Bundler may fail with “You have already activated erb” when the adapter in database.yml uses ERB to Bundler may fail with "You have already activated erb" when the adapter in database.yml uses ERB
Actions

Also available in: Atom PDF