This project is archived and is in readonly mode.

#336 ✓wontfix
Kazuhiro Nishiyama

missing SomeModel#id after reset_subclasses

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

Removing auto defined methods should use remove_method instead of undef_method.

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

Comments and changes to this ticket

  • Kazuhiro Nishiyama

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

    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.

  • Pratik

    Pratik July 12th, 2008 @ 01:38 AM

    • 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.

  • Kazuhiro Nishiyama

    Kazuhiro Nishiyama July 14th, 2008 @ 06:26 AM

    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.

  • ogryb

    ogryb October 6th, 2008 @ 04:56 AM

    • 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 }
    
    
  • ogryb

    ogryb October 7th, 2008 @ 09:59 PM

    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?

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages