Re: [CDBI] Deep recursion on subroutine "Class::DBI::_flesh" ; Class::DBI::Pg

[prev] [thread] [next] [Date index for 2006/01/12]

From: Dan Rowles
Subject: Re: [CDBI] Deep recursion on subroutine "Class::DBI::_flesh" ; Class::DBI::Pg
Date: 12:41 on 12 Jan 2006
I've had "deep recursion on _flesh" problems when I've had a 
"before_create" trigger that calls accessor methods on my object. 
Somethhing like:-

__PACKAGE__->add_trigger("before_create" => sub {
     my $this = shift;
     $this->id(GenUUID()) unless $this->id;
});

usually is the cause of the problem (for me at any rate).

If you do have this, then you have two options - only use calls to 
"_attr" and "_attribute_store" in "before_create" triggers (a pain if 
you want to re-use validation code), or you can try putting this piece 
of code into your App::DBI class, and see if it fixes it:-

sub _flesh {
     my $this = shift;
     if(ref($this) && $this->_undefined_primary) {
         $this->call_trigger("select");
         return $this;
     }
     return $this->SUPER::_flesh(@_);
}

Hope this helps,

Dan





Cedric Boudin wrote:
> Dear list member,
> 
> I do get this message by running my script:
> ------
> Issuing rollback() for database handle being DESTROY'd without explicit
> disconnect() at /usr/local/share/perl/5.8.7/Ima/DBI.pm line 315.
> Deep recursion on subroutine "Class::DBI::_flesh" at
> /usr/local/share/perl/5.8.7/Class/DBI.pm line 818.
> Deep recursion on anonymous subroutine at
> /usr/local/share/perl/5.8.7/Class/DBI.pm line 830.
> ------------------
> 
> The roll back is triggered by an insertion violating a unique constraint
> on two columns in the inserted table.
> I do this on purpouse and want to catch the error with Exception::Class::DBI
> I'm using
> Class::DBI::Pg
> and do try to exploit the 'OOiness' of Postgres.
> Here is how I've structured the tables and the classes.
> DB
> on Top level: table Person, table additional_data
> underneath: table Member inherits Person, additional_data
> Class::DBI
> Top Level: App::DBI
> below:
> - App::Person isa App::DBI
> - App::Member isa App::Person
> 
> the insert is done by like this
> my $member=App::Member->new()
> eval {
>     $member->insert({col1 =>'col1',col2=>'col2'..});
> }
> if ($@){
> ...
> }
> 
> in App::DBI I've configured my connection like this
> __PACKAGE__->connection("dbi:Pg:dbname=ego",
>                         'ego',
>                         'ego',
>                         { PrintError => 0,
>                           RaiseError => 0,
>                           HandleError => Exception::Class::DBI->handler
>                       });
> The autocommit is not set
> 
> I never come back from my insert, and I suppose the recursion is
> somewhere deep in there.
> I never come to catch my exception.
> 
> What am I doing wrong?
> 
> Side questions:
> - Is "misusing" class::dbi with the Pg OO structure reasonnable
> - Is there a way to automagically enforce
> that in my above described construct the Class Member takes care of the
> member specific attribute of the member instance
> and that person class for it's attributes?
> 
> in advance thank you for your future input
> 
> cedric
> 
> 
> 
> _______________________________________________
> ClassDBI mailing list
> ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

        -- 
        Dan Rowles
Outcome Technologies

_________________________________

t: +44 (0)207 656 2460
f: +44 (0)709 230 6588
m: +44 (0)798 076 8143
e: d.rowles@xxxxxxxxxxxxxxxxxxx.xxx
w: http://www.outcometechnologies.com
BUPA House
15-19 Bloomsbury Way
London WC1A 2BA
_________________________________

***This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed. If you receive this message in error, please return it to the
sender.***

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

Re: [CDBI] Deep recursion on subroutine "Class::DBI::_flesh" ; Class::DBI::Pg
Dan Rowles 12:41 on 12 Jan 2006

Generated at 09:31 on 23 Jan 2006 by mariachi v0.52