Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

missing SomeModel#id after reset_subclasses

#336

Removing auto defined methods should use remove_method instead of undef_method.

Because undef_method removes SomeModel#id and hides ActiveRecord::Base#id.

Reported by Kazuhiro Nishiyama · June 5th, 2008 @ 08:34 AM

State: wontfix
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Kazuhiro Nishiyama
    Kazuhiro Nishiyama

    The attached test case scirpt is an individual script, because test environment is with config.cache_classes = true, but the problem occurs with config.cache_classes = false.

    June 5th, 2008 @ 08:34 AM

  2. Pratik
    Pratik
    • State changed from new to wontfix
    • Assigned user set to Pratik
    • Tag set to 2.0-stable, activerecord, bug, edge, patch

    Why are you calling reset_subclasses ? Can you not just call ActiveSupport::Dependencies.clear ?

    Anyone has thoughts on how to test this ?

    Thanks.

    July 12th, 2008 @ 01:38 AM

  3. Kazuhiro Nishiyama
    Kazuhiro Nishiyama

    Calling reset_subclasses is a minimal case.

    I met this problem with passenger-1.0.5 and rails-2.0.2.

    I do not reproduce the problem with passenger-2.0.1 and rails-2.1.0.

    Thanks.

    July 14th, 2008 @ 06:26 AM

  4. ogryb
    ogryb
    • Tag changed from 2.0-stable, activerecord, bug, edge, patch to 2.0-stable, activerecord, bug, edge, patch

    I'm having a bigger problem with 'reset_subclasses' in the following scenario:

    1. Class A is derived from ActiveRecord
    2. Class B is derived from A

    Class B looks OK when it's created first time. After reset_subclasses is called all methods of class B get deleted, but methods of class A are still there. Next time when class B is used I'm getting exceptions because all methods of class B and 'id' are still missing. It happens only if caching is off (config.cache_classes = false).

    I need to fix it somehow. Please let me know what code is responsible for re-creating a class after it was processed by reset_subclasses. Probably I'll fix it there.

    It happens in Rails 2.0.2 and 2.1.1 with both ruby 1.8.7 and 1.8.6.

    If you know any other "work around" please let me know too.

    Below is the piece of code that cripples my classes:

    def self.reset_subclasses #:nodoc: ....

        klass.instance_methods(false).each { |m| klass.send :undef_method, m }
    
    

    October 6th, 2008 @ 04:56 AM

  5. ogryb
    ogryb

    I've changed undef_method to remove_method, but it didn't help - I'm still getting NoMethodError for the methods that are defined in class B.

    Any other ideas?

    October 7th, 2008 @ 09:59 PM