[Dbix-class] DBIx::Class 0.08100 released to CPAN

Matt S Trout dbix-class at trout.me.uk
Tue Apr 21 12:08:28 GMT 2009


On Mon, Apr 20, 2009 at 03:18:01PM -0700, David Ihnen wrote:
> Okay, I have a question playing with this release.
> 
> We have observed that if you attempt to create-related a new row in a 
> table that has a belongs-to to a third table - and omit the hash entry 
> for the relationship column id in question entirely - we get an error:
> 
> DBIx::Class::Relationship::Accessor::__ANON__(): Column donor_id not 
> loaded or not passed to new() prior to insert() on 
> DB::Schema::ivr_schedule=HASH(0x7f895b9c72e8) trying to resolve 
> relationship (maybe you forgot to call ->reload_from_storage to get 
> defaults from the db) at /var/www/samp/DB/Schema/ivr_schedule.pm line 345
> 
> BUT - if we *do* put the hash entry in for the relationship tying column 
> (donor_id in this case) - but leave its value undefined - the error does 
> not occur.
> 
> What do you make of that?

It's a feature.

If you don't supply an explicit undef, DBIC can't know what the value in
the database is - you could have a default of something else, or a trigger
could set it, or whatever.

Which means loading the relationship assuming it was NULL is wrong.

So DBIx::Class now die()s rather than giving undefined and potentially
dangerous/incorrect behaviour.

The code underlying this behaviour also fixes a number of other potentially
dangerous bugs, for example trying to inflate a belongs_to when you didn't
load that column (by passing a limited select => list).

I'm aware this isn't entirely backwards compatible, but it resolves a lot
of bugs, and only really makes existing bugs-in-potentia obvious rather
than breaking code that was correct, so I'm not really willing to revert
it entirely - does anybody have a suggestion for fixing the backcompat
without re-bugging the other cases?

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list