[Dbix-class] find_or_create bug in Alex Povolotsky's code

Matt S Trout dbix-class at trout.me.uk
Sun Apr 6 21:21:06 BST 2008


On Fri, Apr 04, 2008 at 01:29:32PM +0400, Alex Povolotsky wrote:
> Nigel Metheringham wrote:
> >
> >On 3 Apr 2008, at 16:30, Alex Povolotsky wrote:
> >>Attempt to insert into postgres table with undef's for columns with 
> >>default values yields an error. It is especially bad with 
> >>find_or_create sub.
> >>
> >>I've made and tested a simple patch, it looks working ok.
> >
> >
> >So the problem is that when you *explicitly* set column values to 
> >undef (NULL), DBIC does not magically put default values in place?
> >
> >Adding that (and the patch only touches Pg - thus making Pg behave 
> >differently to all the other databases) appears like too much (or 
> >inappropriate) magic to me.
> >
> >I'd be happier with something that generically puts default values in 
> >when the key/value to insert was missed out altogether, but in general 
> >I tend to let the DB do that.  At present it looks like default_value 
> >is used only by deploy.
> 
> As far as I've understood the problem, it's because of "street SQL" used 
> by MySQL. For auto_increment fields, NULL on insert mean "insert next 
> key", the same as DEFAULT. However, it is against SQL standards. Since 
> DBIx::Class was, most likely, developed for MySQL, and tested on it, 
> that bug was missed.

Actually, what you're asking is for DBIC to -emulate- that 'street SQL'
style on non-MySQL DBs. No, sorry, Postgres is correct. DBIC is correct.
Your code isn't. You can tell this by the fact that your code would work
against MySQL, but running it against an actual database doesn't.

This is not a bug anywhere except in your code.

Please expect any further argument on this to be met with a response of
'piss off'.

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