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

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

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

Comments

Projects
None yet
7 participants
@yxhuvud
Copy link

yxhuvud commented Jan 14, 2013

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

This comment has been minimized.

Copy link
Member

steveklabnik commented Jan 14, 2013

Class.new(ActiveRecord::Base)

😢

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

@jonleighton

This comment has been minimized.

Copy link
Member

jonleighton commented Jan 18, 2013

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

This comment has been minimized.

Copy link
Contributor

thedarkone commented Jan 19, 2013

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

This comment has been minimized.

Copy link
Member

rafaelfranca commented Jan 19, 2013

I agree with @thedarkone

@tenderlove

This comment has been minimized.

Copy link
Member

tenderlove commented Jan 19, 2013

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

@ghost ghost assigned tenderlove Jan 19, 2013

@yxhuvud

This comment has been minimized.

Copy link

yxhuvud commented Jan 19, 2013

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.

tenderlove added a commit that referenced this issue Jan 20, 2013

guilleiguaran added a commit that referenced this issue Jan 20, 2013

@guilleiguaran

This comment has been minimized.

Copy link
Member

guilleiguaran commented Jan 20, 2013

Closing this since #9002 was merged

mcary pushed a commit to mcary/wolverine that referenced this issue Mar 21, 2017

Marcel M. Cary
Fix error with annonymous ActiveRecord classes
I'm seeing this error while running any spec for ActiveRecord Source or
Sink classes:

    Anonymous class is not allowed

The problem is that support for "Class.new(ActiveRecord::Base)"
(aka anonymous subclasses) was dropped in recent versions of Rails.
(rails/rails#8934)

Find another way to generate AR classes.

mcary pushed a commit to mcary/wolverine that referenced this issue Mar 21, 2017

Marcel M. Cary
Fix error with annonymous ActiveRecord classes
I'm seeing this error while running any spec for ActiveRecord Source or
Sink classes:

    Anonymous class is not allowed

The problem is that support for "Class.new(ActiveRecord::Base)"
(aka anonymous subclasses) was dropped in recent versions of Rails.
(rails/rails#8934)

Find another way to generate AR classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment