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
database.yml gets evaluated before initializers run since Rails 7.1.0 #51578
Comments
This is expected. Prior to 7.1, if you had multiple databases in an environment (e.g. Rails 7.1 gets around this by loading
When you actually run a task like So no, nothing breaks. |
Alright so it doesn't matter if the dummy does not get proper credentials? Not sure what the best course of action is for us but it does break if your initializer defines something your yml attempts to use like a config object (that doesn't ignore missing keys). Like I can use |
That is strange. The dummy config thing should not have changed the order. Did you find the commit that changed this behavior? |
@rafaelfranca it's not that the order has changed, it's that the ERB is no longer being stripped out (on initial database.yml load). Here's the commit that changes it: #46134 |
I just wanted to confirm the change that introduced the change of behavior. @2called-chaos if you custom configuration is inside |
This was totally wrong. I understand it now. Here's the proper explanation: Let's say you have a constant in an initializer named In Rails 7.1, the ERB values in database.yml are not replaced, so when it is initially loaded, you'll get |
Steps to reproduce
<% puts "database.yml" %>
puts "initializer"
rails db:migrate
orrails db:create
on <7.1 (e.g. 7.0.8.1) and >= 7.1.0Expected behavior (as was the case <7.1)
Initializers run before database.yml gets interpreted by ERB.
Actual behavior (since 7.1)
Initializers now run after database.yml has been interpreted by ERB
System configuration
Rails version: 7.0.8.1, 7.1.0, 7.1.3.2
Ruby version: 3.3.0
Not sure if this is intended but as far as I can tell not documented. This obviously breaks if you attempt to use config data sourced and/or configured by an initializer in your database.yml.
The text was updated successfully, but these errors were encountered: