Connection pool breaks with classes created with Class.new(ActiveRecord::Base) #8934

Closed
yxhuvud opened this Issue Jan 14, 2013 · 7 comments

7 participants

@yxhuvud

retrieve_connection_pool in connection_pool.rb look up connection pool by class name. However, class name is the empty string if the class is created with Class.new(ActiveRecord::Base). If several classes are created that way using different databases, then massive confusion will occur.

I see two possible resolutions to this:
1: Enforce name being != "" when executing estrablish_connection
2: use object_id instead of class name.

Not the biggest issue I guess since it is quite a bit off the normal path of doing things, but it is still not very nice to get silent breakage.

@steveklabnik
Ruby on Rails member

Class.new(ActiveRecord::Base)

😢

@jonleighton @tenderlove is this a case we want to support?

@jonleighton
Ruby on Rails member

We use the class name to avoid memory leaks in development mode. I guess a better solution would be to use ActionDispatch::Reloader to clear the cache of the connection handler.

@thedarkone

I'm not sure we should be supporting "anonymous" AR classes since a sizable chunk of AR code depends on each class having a proper name (guessing table names, guessing and looking up relation classes, etc).

@rafaelfranca
Ruby on Rails member

I agree with @thedarkone

@tenderlove
Ruby on Rails member

Ya, let's not support anonymous classes for now. I will have people change this to raise an exception.

@tenderlove tenderlove was assigned Jan 19, 2013
@yxhuvud

As long as noone else has to to the error searching I had to do, I'm happy.

I'd prefer if it is kept at a simple check that .name isn't returning the empty string though, since that seems to be the only showstopper.

@guilleiguaran
Ruby on Rails member

Closing this since #9002 was merged

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