#787 ✓not-applicable
Gary Yngve

load errors cause incomplete STI

Reported by Gary Yngve | January 27th, 2009 @ 03:02 AM

A framework like Merb has a circular queue that keeps on trying to load files (models) until they all load, so that dependencies are resolved.

What can happen is that a model will be incompletely loaded/required, crash because of a dependency, the subclass will load (the constant has been defined already), and then the original model will reload.

I'm not sure there's an easy fix, as an incomplete load followed by a reload isn't too much different than a monkey patch.

Attached is a demo script:

Comments and changes to this ticket

  • Gary Yngve

    Gary Yngve January 27th, 2009 @ 03:14 AM

    One more comment:

    a user can help prevent this bug from occurring by: 1) putting all properties at the top of a model file 2) making sure to specify :class_name=>"Foo" instead of :class_name=>Foo for associations (coincidentially both are equivalent if Foo is defined).

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 21st, 2009 @ 02:31 AM

    • State changed from “unconfirmed” to “not-applicable”

    I have considered adding a const_missing method to DM::Model so that you could reference a not-yet-loaded model. We would need to track all references and not-used constants though and blow up at some later point if they were never loaded. It would probably be a bit tricky to get right. However in the foreseeable future I can't see adding this until the 0.10.0 series has stabilized, and perhaps not until after 1.0 is released.

    For now the :class_name should always be a String unless you know the model has been loaded. I believe this is part of the documented API.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

People watching this ticket