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.

Single table inheritance bug only in production environment

#188

With ActiveRecord 2.0.2, define the following classes.

class A < ActiveRecord::Base

class B < A

class C < B

Implement all three with single table inheritance. Create several instances of B and of C and save them in the database.

Call B.find(:all) in a controller list action.

If a development environment is loaded, then B.find(:all) will always return just objects of class B. Set a breakpoint on B.find(:all) in a debugger to verify this.

If a production environment is loaded, then the first time B.find(:all) is run it will return just objects of class B. However, on subsequent calls to B.find(:all), ActiveRecord returns objects of class C as well. This was checked with a debugger breaking as soon as B.find(:all) was called.

Loading a production environment in the console and running B.find(:all) multiple times seems to work correctly. This bug only occurs when called from within a controller.

Reported by Joshua J. Born · May 13th, 2008 @ 10:32 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Joshua J. Born
    Joshua J. Born

    I'm not sure why this occurred only when Rails was loaded in its production environment and not the development environment, but this seems to be due to the documented foible of ActiveRecord getting subclasses in STI only if the subclass module has been loaded.

    May 13th, 2008 @ 10:45 PM

  2. Joshua J. Born
  3. josh
    josh
    • State changed from new to stale
    • Tag set to activerecord, bug

    Closing this ticket as stale. If this is still an issue for you, feel free to reopen this ticket or create a new one with an updated description. Remember those unit tests too ;)

    July 17th, 2008 @ 01:38 AM

  4. Pete P.
    Pete P.

    I've encountered this problem as well as detailed on this new ticket:

    https://rails.lighthouseapp.com/...

    April 1st, 2009 @ 04:33 AM