[CDBI] Class::DBI->_init called from Class::DBI->_insert

Andy Sanders Andy.Sanders at semantico.com
Mon Nov 21 17:21:52 GMT 2005


Hi all,

We have been getting errors from Class::DBI->insert() regarding null 
values not being allowed in a particular field.  However, we are sure 
that we are passing in a value for that field.  (That the error message 
actually includes the field and its value makes us doubly sure).

We have been looking through the Class::DBI source code and traced what 
we think is happening:

Class::DBI->_insert calls Class::DBI->_init.  _init looks in the 
Live_Object cache for an existing instance.  Subsequently, _insert 
checks the returned object to see if each attribute exists.  However, 
objects coming from the cache do not always have all the attributes present.

We have made the following modification and our problem seems to have 
gone away.  Unfortunately, we are totally unfamiliar with how Class::DBI 
works. Does this change make sense to anyone who does understand Class::DBI?

(Class::DBI Version: 3.0.12)

--- Class/DBI.pm	2005-11-04 09:22:56.000000000 +0000
+++ Class/DBI.pm	2005-11-21 16:43:23.474295972 +0000
@@ -531,7 +531,10 @@
         my ($proto, $data) = @_;
         my $class = ref $proto || $proto;

-       my $self = $class->_init($data);
+       my $self = $class->_fresh_init(
+           $class->_live_object_key($data),
+           $data,
+       );
         $self->call_trigger('before_create');
         $self->call_trigger('deflate_for_create');

Thanks,

Andy


-- 
Andy Sanders
Software Engineer
Semantico
Lees House
21-23 Dyke Road
Brighton BN1 3FE
Sussex  UK

Tel: +44 (0)1273 722222 x208
Fax: +44 (0)1273 723232
Email: Andy.Sanders at semantico.com
Web: http://www.semantico.com/




More information about the ClassDBI mailing list