-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
core_ext/class.rb:subclasses conflicts with ActiveRecord #4741
Comments
it was really meant to be ~ internal, aj guess 😉 ... for @enebo we probably only want this for 9.2 or do you have a string preference for getting this into 9.1.13? |
OK so its part of JRuby's core extension API ... it can not be simply removed in another release. |
@kares yeah I think part of the solution will be to deprecate on our side and replace it with something which does not conflict. Since we have been exposing this as a public method for many years (since at least 2011?) now this is unfortunate. I am always amazed how long it takes for someone to notice these issues but perhaps AS + jrubyc is uncommon? |
@kares oh we should get each_object usage into 9.1.13.0 internally and not use subclasses. At that point people can include jruby/core_ext before AS is loaded and have AS win while not making anything on our side stop working. So if you plan on changing our internal consumer(s) then please cp that commit to jruby-9.1.13.0 branch. |
@enebo I was wrong, JRuby is actually not using
... which are just generated (included) modules - should be fine to get them excluded although not 100% sure |
In fact, it includes only the generated modules - they are 1:1 with all the subclasses of ActiveRecord::Base in my use case and the generated modules don't have 'subclasses' defined anymore after jruby/core_ext is loaded after AS is up. We're working around this by not using 'subclasses' but rather implementing our own as active record is coming in very early and jruby/core_ext is only in one of our modules. For example, in the test case I put in, there is only one subclass returned - the generated module and it's missing table_name. |
the underlying issue is that we return the raw subclasses collection that a RubyClass manages internally.
for 9.2 JRuby might deprecate Class#subclasses altogether (provide a non core-ext polluting alternative). |
implementation has been changed but old behavior can be achieved ... using `klass.to_java.sublclasses` (not very useful for user-code) also synchronize subclasses retrieval on RubyClass ~ rest of related impl resolves jruby#4741
implementation has been changed but old behavior can be achieved ... using `klass.to_java.sublclasses` (not very useful for user-code) also synchronize subclasses retrieval on RubyClass ~ rest of related impl resolves jruby#4741
@enebo willl be back-porting the patch to 9.1.13 (will change the target after its done) to make JRuby's |
landed as 916b1e1 |
I need to point out that this new subclasses impl will be much slower than the built-in version due to the cost of running the each_object block. That may or may not matter for typical uses. Under the covers, each_object for a class just does what the old subclasses did, but the Ruby code could be more efficient. Has this been backported to 9.1 branch yet? |
yep, backported. |
Environment
Expected Behavior
After
require 'jruby/core_ext'
ActiveRecord::Base.subclasses
should continue to return an array of the ActiveRecord::Base subclasses but instead returns the Java subclasses of ActiveRecord::Base that do not have the same methods available on them anymore.Analysis
JRuby is defining
subclasses
at:https://github.com/jruby/jruby/blob/f7746d0be94f5d9f7cd27af610f1bc5dd2622794/lib/ruby/stdlib/jruby/core_ext/class.rb#L31
ActiveRecord is also defining
subclasses
at:https://github.com/rails/rails/blob/cfb1e4dfd8813d3d5c75a15a750b3c53eebdea65/activesupport/lib/active_support/core_ext/class/subclasses.rb#L50
JRuby really shouldn't be messing up ActiveRecord's
subclasses
call if it breaks ActiveRecord usage.The text was updated successfully, but these errors were encountered: