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

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

From: Cedric Boudin
Subject: Re: [CDBI] Deep recursion on subroutine "Class::DBI::_flesh" ; Class::DBI::Pg
Date: 13:46 on 12 Jan 2006
Dan Rowles wrote:

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

I needed also a trigger before create.
But in my case I did not do it because I need it at the Person level.
As the insert is done at member level (at least in this version of my
thoughts, hence my "side questions")
so to have it working
I must put it at the member level and for the next child class of person
on the same level as member I must have it again.
this leads to same code in different places not so nice.
So I did put my trigger in the db where by the way I have the same
problem of inheritance :=)

so there are no before create trigger in cdbi for this class

>
> 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(@_);
> }
>
I tried this and magically it works I can catch my exception.
I'll deeply impressed and grateful.

Have a succesfull 2006

cedric


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


_______________________________________________
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
Cedric Boudin 13:46 on 12 Jan 2006

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