Skip to content

Commit

Permalink
The Pool Config no longer keeps a reference to the connection class.
Browse files Browse the repository at this point in the history
Keeping a reference to the class caused subtle issues when combined with reloading in
development. Instead, cache the name and whether it's primary.

Fixes rails#54343.
  • Loading branch information
flavorjones committed Jan 24, 2025
1 parent cd171d6 commit bbd4afe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* The Pool Config no longer keeps a reference to the connection class.

Keeping a reference to the class caused subtle issues when combined with reloading in
development. Fixes #54343.

*Mike Dalessio*

* Eliminate queries loading dumped schema cache on Postgres

Improve resiliency by avoiding needing to open a database connection to load the
Expand Down
16 changes: 12 additions & 4 deletions activerecord/lib/active_record/connection_adapters/pool_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class PoolConfig # :nodoc:

attr_reader :db_config, :role, :shard
attr_writer :schema_reflection, :server_version
attr_accessor :connection_class

def schema_reflection
@schema_reflection ||= SchemaReflection.new(db_config.lazy_schema_cache_path)
Expand All @@ -29,7 +28,7 @@ def disconnect_all!
def initialize(connection_class, db_config, role, shard)
super()
@server_version = nil
@connection_class = connection_class
self.connection_class = connection_class
@db_config = db_config
@role = role
@shard = shard
Expand All @@ -41,11 +40,20 @@ def server_version(connection)
@server_version || synchronize { @server_version ||= connection.get_database_version }
end

def connection_class=(connection_class)
@connection_class_name = connection_class.name
@connection_class_primary_p = connection_class.primary_class?
end

def connection_class
@connection_class_name.constantize
end

def connection_name
if connection_class.primary_class?
if @connection_class_primary_p
"ActiveRecord::Base"
else
connection_class.name
@connection_class_name
end
end

Expand Down

0 comments on commit bbd4afe

Please sign in to comment.