[jifty-devel] Re: Virtual models chicken-egg problem with references

Jesse Vincent jesse at bestpractical.com
Tue Nov 20 13:56:13 EST 2007


It's a fairly hairy codepath, but having it covered is better than not.

+1


On Tue, Nov 20, 2007 at 12:20:14PM -0600, Andrew Sterling Hanenkamp wrote:
> So, my first patch was crap. It was actually failing because of a number of
> typos. However, I have a second patch that both reveals the problem and now
> fixes it, I think. I'm dropping it here to get feedback on how it looks,
> mostly because the new second-run.t test I've added to
> TestApp::DatabaseBackedModels is kind of kludgey and wondered if anybody had
> a better way.
> 
> The new second-run.t test checks to see if a second run of Jifty after Jifty
> has been bootstrapped will load the models correctly. It does not in the
> current repository since collections aren't necessarily required before they
> are used. To do this, I fork inside the test after including Jifty::Test to
> bootstrap the database and run a second-run.pl child process with
> essentially the same tests as bootstrap.t. In order to make the second run
> work without bootstrapping, I've also built a custom subclass of Jifty::Test
> called TestApp::DatabaseBackedModels::Test that overrides setup() to run
> without the database setup and _testfile_to_dbname() so that the test will
> use the same database as the parent process already bootstrapped.
> 
> I could probably eliminate the need for TestApp::DatabaseBackedModels::Test
> with an environment flag similar to the JIFTY_FAST_TEST variable.
> 
> Cheers,
> Andrew
> 
> On Nov 19, 2007 11:41 PM, Andrew Sterling Hanenkamp <sterling at hanenkamp.com>
> wrote:
> 
> > Jesse,
> >
> > I'm working on a problem I've discovered in the V-M branch. I've attached
> > a patch that contains a new bootstrap.t test and modified Bootstrap.pm for
> > TestApp::DatabaseBackedModels to reveal the basic issue. But here's the
> > jist. The patch basically modifies the existing boostrapper to add an
> > additional "Warehouse" model similar to these declared models:
> >
> > package Warehouse;
> > schema {
> >   column location => type is 'text';
> >   column widgets => references WidgetCollection by 'warehouse';
> > };
> >
> > package Widget;
> > schema {
> >   column name => type is 'text';
> >   column inventory => type is 'int';
> >   column warehouse => references Warehouse;
> > };
> >
> > This code when used works fine until you try to call the "widgets" method
> > of a "Warehouse" object. When you do that you get:
> >
> > WARN - DBD::SQLite::db prepare failed: no such column: widgets(1) at
> > dbdimp.c line 271 at /Library/Perl/5.8.6/Jifty/DBI/Handle.pm line 474.
> > WARN - TestApp::DatabaseBackedModels::Handle=HASH(0x1f69ea8) couldn't
> > prepare the query 'SELECT widgets FROM warehouses WHERE id = ?'no such
> > column: widgets(1) at dbdimp.c line 271
> >
> > As you can see the anonymous subroutine used to define "widgets" is
> > incorrectly using a call to __value() to fetch the value rather than using
> > _collection_value() as it should. I've not pinned this all the way down yet,
> > but I'm speculating that the issue is that the "widgets" column is being
> > defined prior to "WidgetCollection" becoming available inside
> > Jifty::ClassLoader::require_classes_from_database().
> >
> > What I don't know is how to fix it, if this is indeed the case. I'm
> > currently working my way through Jifty::DBI::Schema to understand how the
> > _init_column() method and related code works to see if I can bring the same
> > or similar logic into the class loader, but I'd be grateful for some advice.
> >
> >
> > Cheers,
> > Andrew
> >


> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel


-- 


More information about the jifty-devel mailing list