activerecordruby-on-rails-7ruby-upgrade

No connection pool for 'ActiveRecord::Base' found for the ' ' role


I upgraded our rails application from version 6.0 directly to 7.0. After commenting out the new framework defaults everything seemed to work smoothly but after setting the load_defaults to 7.0 I got the error: No connection pool for 'ActiveRecord::Base' found for the '' role. This let's my application fail on start.

I tried setting config.active_record.legacy_connection_handling = true and this made the application run smooth again but of course I get a deprecation warning from this. I also verified our database.yml but this seems alright too. Has anybody experience with this error message or knows how to resolve it?


Solution

  • I needed a bit of research but it looks like the error was caused by one of our models which defined the class method default_role. The problem with the naming of this method is, that is named like the method which rails uses to return the default role which is also named default_role.

    Now whenever our model wanted to access one of the connections from the connection pool, the role for the searched connection pool was nil since we overwrote the rails method in our model. This led to the above error that no connection for the '' role was found.