Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 68946
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: karl.forner [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: set_inflated_columns do not clear columns
When you have an inflated column, such as "date_message", { data_type => "DATE", default_value => "SYSDATE", is_nullable => 1, size => 19, }, using DBIx::Class::InflateColumn::DateTime, the only way to clear the date_message column is to use $obj->date_message(undef) or $obj->set_inflated_column('date_message' => undef). BUT if you do $obj->set_inflated_columns({date_message => undef}); it WILL NOT clear the column because if ignores all non scalar values, cf the line "if (ref $upd->{$key}) {" in the set_inflated_columns function. So IMHO this is plainly wrong because one thinh that these two calls are equivalent, and moreover the values are silently ignored. sub set_inflated_columns { my ( $self, $upd ) = @_; foreach my $key (keys %$upd) { if (ref $upd->{$key}) { my $info = $self->relationship_info($key); my $acc_type = $info->{attrs}{accessor} || ''; if ($acc_type eq 'single') { my $rel = delete $upd->{$key}; $self->set_from_related($key => $rel); $self->{_relationship_data}{$key} = $rel; } elsif ($acc_type eq 'multi') { $self->throw_exception( "Recursive update is not supported over relationships of type '$acc_type' ($key)" ); } elsif ($self->has_column($key) && exists $self->column_info($key)->{_inflate_info}) { $self->set_inflated_column($key, delete $upd->{$key}); } } } $self->set_columns($upd); }
On Mon Jun 20 05:11:10 2011, karl.forner@gmail.com wrote: Show quoted text
> When you have an inflated column, such as > "date_message", > { > data_type => "DATE", > default_value => "SYSDATE", > is_nullable => 1, > size => 19, > }, > using DBIx::Class::InflateColumn::DateTime, > the only way to clear the date_message column > is to use $obj->date_message(undef) or > $obj->set_inflated_column('date_message' => undef). > > BUT if you do $obj->set_inflated_columns({date_message => undef}); > it WILL NOT clear the column because if ignores all non scalar values, > cf the line "if (ref $upd->{$key}) {" in the set_inflated_columns > function.
This makes no sense... set_inflated_columns() ends up calling set_inflated_column here: https://github.com/dbsrgits/dbix-class/blob/master/lib/DBIx/Class/Row.pm#L994 which then calls set_column (with the deflated value which in your case is undef) here: https://github.com/dbsrgits/dbix-class/blob/master/lib/DBIx/Class/InflateColumn.pm#L152 Can you insert some debug statements in strategic places and provide more info on what exactly fails for you (or alternatively write a failing test based on: https://github.com/dbsrgits/dbix-class/blob/master/t/inflate/core.t#L55 Cheers
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 10:49:39 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Karl Forner <karl.forner [...] gmail.com>
Hi No it does notL check the call, if the value is undef (or ''), the only way apparently to clear a column, then line 983 "if (ref $upd->{$key}) {" prevents the call to set_inflated_column. I have traced the calls to the set_inflated_column() so I'm pretty sure of my claim. Best, Kar; On Wed, Jun 22, 2011 at 5:18 AM, Peter Rabbitson via RT < bug-DBIx-Class@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=68946 > > > On Mon Jun 20 05:11:10 2011, karl.forner@gmail.com wrote:
> > When you have an inflated column, such as > > "date_message", > > { > > data_type => "DATE", > > default_value => "SYSDATE", > > is_nullable => 1, > > size => 19, > > }, > > using DBIx::Class::InflateColumn::DateTime, > > the only way to clear the date_message column > > is to use $obj->date_message(undef) or > > $obj->set_inflated_column('date_message' => undef). > > > > BUT if you do $obj->set_inflated_columns({date_message => undef}); > > it WILL NOT clear the column because if ignores all non scalar values, > > cf the line "if (ref $upd->{$key}) {" in the set_inflated_columns > > function.
> > This makes no sense... > > set_inflated_columns() ends up calling set_inflated_column here: > > https://github.com/dbsrgits/dbix-class/blob/master/lib/DBIx/Class/Row.pm#L994 > > which then calls set_column (with the deflated value which in your case > is undef) here: > > https://github.com/dbsrgits/dbix-class/blob/master/lib/DBIx/Class/InflateColumn.pm#L152 > > Can you insert some debug statements in strategic places and provide > more info on what exactly fails for you (or alternatively write a > failing test based on: > https://github.com/dbsrgits/dbix-class/blob/master/t/inflate/core.t#L55 > > Cheers > >
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 14:19:10 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Peter Rabbitson <ribasushi [...] cpan.org>
karl.forner@gmail.com via RT wrote: Show quoted text
> Queue: DBIx-Class > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=68946 > > > Hi > > No it does notL check the call, if the value is undef (or ''), the only way > apparently to clear a column, > then line 983 "if (ref $upd->{$key}) {" prevents the call to
Yes, you do descend into this if-branch, and then you have: 984 if ($acc_type eq 'single') { 985 my $rel = delete $upd->{$key}; 986 $self->set_from_related($key => $rel); 987 $self->{_relationship_data}{$key} = $rel; 988 } 989 elsif ($acc_type eq 'multi') { 990 $self->throw_exception( 991 "Recursive update is not supported over relationships of type '$acc_type' ($key)" 992 ); 993 } 994 elsif ($self->has_column($key) && exists $self->column_info($key)->{_inflate_info}) { 995 $self->set_inflated_column($key, delete $upd->{$key}); 996 } Of which you should hit the last elsif (line 994-996 in current master) Please read the rest of my email, and provide me with more info. Without the ability to see and/or replicate the problem I am afraid we are not going to be able much in terms of fixing it.
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 14:50:26 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Karl Forner <karl.forner [...] gmail.com>
Show quoted text
> No it does notL check the call, if the value is undef (or ''), the only > way
> > apparently to clear a column, > > then line 983 "if (ref $upd->{$key}) {" prevents the call to
> > Yes, you do descend into this if-branch, and then you have: >
Sorry, that's what I do not understand. Do you agree that $upd->{$key} == undef, so that it DOES not descend into the if-branch (and there is no elsif) ? Because I believe that ref(undef) is false ? Concerning the test case, I thought it was pretty obvious, but if you think it is necessary I can write one. Just tell me. Best, Karl
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 14:53:46 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Peter Rabbitson <ribasushi [...] cpan.org>
karl.forner@gmail.com via RT wrote: Show quoted text
> Queue: DBIx-Class > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=68946 > >
>> No it does notL check the call, if the value is undef (or ''), the only >> way
>>> apparently to clear a column, >>> then line 983 "if (ref $upd->{$key}) {" prevents the call to
>> Yes, you do descend into this if-branch, and then you have: >>
> > Sorry, that's what I do not understand. Do you agree that $upd->{$key} == > undef, so that it DOES not descend into the if-branch (and there is no > elsif) ? Because I believe that ref(undef) is false ?
Sorry not enough coffee - so yes, it will not descend there, and instead will do $self->set_columns($upd), which will blow away the inflated value as well. So I still do not see a problem. Also - which version of DBIC are you running? Show quoted text
> Concerning the test case, I thought it was pretty obvious, but if you think > it is necessary I can write one. Just tell me.
A test case will have to be written anyway, even if "obvious". Please do so if time permits, it will speed up the fix a lot.
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 20:06:50 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Karl Forner <karl.forner [...] gmail.com>
Hi, Guess what: you were right set_columns() is fixed in the last DBIx::Class version. Unfortunately I can not upgrade it because my schema is not incompatible (DBIx::Class::PK::id(): Unable to uniquely identify row object with missing PK columns) and my hacked script that generates the schema no longer works either. It is not that bad because I'm using a custom update() method that cares about that problem. Many thanks, Keep on the good work, Karl On Wed, Jun 22, 2011 at 2:53 PM, Peter Rabbitson via RT < bug-DBIx-Class@rt.cpan.org> wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=68946 > > > karl.forner@gmail.com via RT wrote:
> > Queue: DBIx-Class > > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=68946 > > >
> >> No it does notL check the call, if the value is undef (or ''), the only > >> way
> >>> apparently to clear a column, > >>> then line 983 "if (ref $upd->{$key}) {" prevents the call to
> >> Yes, you do descend into this if-branch, and then you have: > >>
> > > > Sorry, that's what I do not understand. Do you agree that $upd->{$key} == > > undef, so that it DOES not descend into the if-branch (and there is no > > elsif) ? Because I believe that ref(undef) is false ?
> > Sorry not enough coffee - so yes, it will not descend there, and instead > will do $self->set_columns($upd), which will blow away the inflated value > as well. > > So I still do not see a problem. Also - which version of DBIC are you > running? >
> > Concerning the test case, I thought it was pretty obvious, but if you
> think
> > it is necessary I can write one. Just tell me.
> > A test case will have to be written anyway, even if "obvious". Please > do so if time permits, it will speed up the fix a lot. > >
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 20:14:21 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Peter Rabbitson <ribasushi [...] cpan.org>
karl.forner@gmail.com via RT wrote: Show quoted text
> Queue: DBIx-Class > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=68946 > > > Hi, > > Guess what: you were right set_columns() is fixed in the last DBIx::Class > version. > > Unfortunately I can not upgrade it because my schema is not incompatible > (DBIx::Class::PK::id(): Unable to uniquely identify row object with missing > PK columns) > and my hacked script that generates the schema no longer works either.
There's no such thing as "incompatible schema" - we either planted a regression (which needs to be fixed) or latest dbic exposed a hidden issue with your existing code (which needs to be fixed). The error in question is indeed new - before when an object was missing some of its PK values (not NULL, but missing as in DBIC has no idea what they are) - we would merrily assume NULL and keep going. This is pretty much never the right thing to do. I strongly suggest you investigate this error further, as it is a good indicator that you have hidden problems in your current codebase. Cheers
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 20:23:30 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Karl Forner <karl.forner [...] gmail.com>
Show quoted text
> > Unfortunately I can not upgrade it because my schema is not incompatible > > (DBIx::Class::PK::id(): Unable to uniquely identify row object with
> missing
> > PK columns) > > and my hacked script that generates the schema no longer works either.
> > There's no such thing as "incompatible schema" - we either planted > a regression (which needs to be fixed) or latest dbic exposed a hidden > issue with your existing code (which needs to be fixed). > >
from what I've quickly seen, the (automatically generate) schema misses the 'set_primary_key()'statements, but all the other keys are flagged as foreign keys, so I guess it is all right. Moreover I have plenty of regression tests and the application is working for years so... But you're right, I should plan a migration plan, but it is not minor because it involves updating Catalyst/DBIx::Class/DBD::Oracle/Moose and all my dirty little hacks would give em headaches. Cheers, Karl Show quoted text
> The error in question is indeed new - before when an object was missing > some of its PK values (not NULL, but missing as in DBIC has no idea what > they are) - we would merrily assume NULL and keep going. This is pretty > much never the right thing to do. I strongly suggest you investigate this > error further, as it is a good indicator that you have hidden problems > in your current codebase. > > Cheers > >
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 20:26:17 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Peter Rabbitson <ribasushi [...] cpan.org>
karl.forner@gmail.com via RT wrote: Show quoted text
> Queue: DBIx-Class > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=68946 > >
>>> Unfortunately I can not upgrade it because my schema is not incompatible >>> (DBIx::Class::PK::id(): Unable to uniquely identify row object with
>> missing
>>> PK columns) >>> and my hacked script that generates the schema no longer works either.
>> There's no such thing as "incompatible schema" - we either planted >> a regression (which needs to be fixed) or latest dbic exposed a hidden >> issue with your existing code (which needs to be fixed). >> >>
> from what I've quickly seen, the (automatically generate) schema misses the > 'set_primary_key()'statements,
This is *quite* bad. Consider the following (this has been the case for years, it just got documented/sanity-checked recently): http://search.cpan.org/~frew/DBIx-Class-0.08192/lib/DBIx/Class/Manual/Intro.pod#The_Significance_and_Importance_of_Primary_Keys
Subject: Re: [rt.cpan.org #68946] set_inflated_columns do not clear columns
Date: Wed, 22 Jun 2011 21:20:59 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Karl Forner <karl.forner [...] gmail.com>
Ok, good to know, thanks !! On Wed, Jun 22, 2011 at 8:26 PM, Peter Rabbitson via RT < bug-DBIx-Class@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=68946 > > > karl.forner@gmail.com via RT wrote:
> > Queue: DBIx-Class > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=68946 > > >
> >>> Unfortunately I can not upgrade it because my schema is not
> incompatible
> >>> (DBIx::Class::PK::id(): Unable to uniquely identify row object with
> >> missing
> >>> PK columns) > >>> and my hacked script that generates the schema no longer works either.
> >> There's no such thing as "incompatible schema" - we either planted > >> a regression (which needs to be fixed) or latest dbic exposed a hidden > >> issue with your existing code (which needs to be fixed). > >> > >>
> > from what I've quickly seen, the (automatically generate) schema misses
> the
> > 'set_primary_key()'statements,
> > This is *quite* bad. Consider the following (this has been the case for > years, it just got documented/sanity-checked recently): > > http://search.cpan.org/~frew/DBIx-Class-0.08192/lib/DBIx/Class/Manual/Intro.pod#The_Significance_and_Importance_of_Primary_Keys > >