breaking change ?

3 messages Options
Embed this post
Permalink
Gerrit Wichert

breaking change ?

Reply Threaded More More options
Print post
Permalink
hello,

im using the following code  for quite some time (about a year) to get
values of two related rows of the same table.
This worked very well. But since the last upgrade of DBIx:_Class to
version 0.08107 it failed with the following error:

DBIx::Class::ResultSet::next(): Column id not loaded or not passed to
new() prior to insert() on
GS::Model::TimeControl::DBIx::TimeSheet=HASH(0x9707b0c) trying to
resolve relationship (maybe you forgot to call ->discard_changes to get
defaults from the db) at ...

changing the select from:
   select => [ qw/ me.login me.host me.type me.mtime end.mtime /],
to
   select => [ qw/ me.login me.host me.type me.mtime end.mtime me.id/],
makes it work again.
So is seems to fail when not including the primary key into the result.

Is this really necessary to select the primary key?
Is it a bug or a breaking change or can i write such requests in a
better way?


And btw. did anyone know of a db-portable way to deflate DateTime values
in where statements?

thanks,
  Gerrit Wichert





package GS::DBIC::Schemata::TimeControl::TimeSheet;

use strict;
use warnings;

use base qw/DBIx::Class/;

__PACKAGE__->load_components(qw/ InflateColumn::DateTime Core /);
__PACKAGE__->table('time');
__PACKAGE__->add_columns( qw/ id login type pid host /);
__PACKAGE__->add_columns(  mtime =>{data_type =>'TIMESTAMP'},);
__PACKAGE__->set_primary_key('id');

__PACKAGE__->belongs_to(
    'end',
    __PACKAGE__,
    {'foreign.pid'=>'self.id'},
    {'join_type' => 'left'}
    );
1;



...
my $rs = $schema->resultset('TimeSheet')->
          search( {'me.login' => $employeeId,
                         'me.pid'   => {'=' => 0},
                         'me.mtime' => {
                                                    '>'  => $date->ymd,
                                                    '<'  =>
$date->clone->add(days=>1)->ymd
                                                   }
                        },
                        { join   => [qw/ end /],        
                          select => [ qw/ me.login me.host me.type
me.mtime end.mtime /],
                        });

while (my $entry = $rs->next) {
...
}  



_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Peter Rabbitson-2

Re: breaking change ?

Reply Threaded More More options
Print post
Permalink
Gerrit Wichert wrote:

> hello,
>
> im using the following code  for quite some time (about a year) to get
> values of two related rows of the same table.
> This worked very well. But since the last upgrade of DBIx:_Class to
> version 0.08107 it failed with the following error:
>
> DBIx::Class::ResultSet::next(): Column id not loaded or not passed to
> new() prior to insert() on
> GS::Model::TimeControl::DBIx::TimeSheet=HASH(0x9707b0c) trying to
> resolve relationship (maybe you forgot to call ->discard_changes to get
> defaults from the db) at ...
>
> changing the select from:
>    select => [ qw/ me.login me.host me.type me.mtime end.mtime /],
> to
>    select => [ qw/ me.login me.host me.type me.mtime end.mtime me.id/],
> makes it work again.
> So is seems to fail when not including the primary key into the result.
>
> Is this really necessary to select the primary key?
> Is it a bug or a breaking change or can i write such requests in a
> better way?
>
>
> And btw. did anyone know of a db-portable way to deflate DateTime values
> in where statements?
>
> thanks,
>   Gerrit Wichert
>
>
>
>
>
> package GS::DBIC::Schemata::TimeControl::TimeSheet;
>
> use strict;
> use warnings;
>
> use base qw/DBIx::Class/;
>
> __PACKAGE__->load_components(qw/ InflateColumn::DateTime Core /);
> __PACKAGE__->table('time');
> __PACKAGE__->add_columns( qw/ id login type pid host /);
> __PACKAGE__->add_columns(  mtime =>{data_type =>'TIMESTAMP'},);
> __PACKAGE__->set_primary_key('id');
>
> __PACKAGE__->belongs_to(
>     'end',
>     __PACKAGE__,
>     {'foreign.pid'=>'self.id'},
>     {'join_type' => 'left'}
>     );
> 1;
>
>
>
> ...
> my $rs = $schema->resultset('TimeSheet')->
>           search( {'me.login' => $employeeId,
>                          'me.pid'   => {'=' => 0},
>                          'me.mtime' => {
>                                                     '>'  => $date->ymd,
>                                                     '<'  =>
> $date->clone->add(days=>1)->ymd
>                                                    }
>                         },
>                         { join   => [qw/ end /],        
>                           select => [ qw/ me.login me.host me.type
> me.mtime end.mtime /],
>                         });
>
> while (my $entry = $rs->next) {
> ...
> }  
>

Hmmm... this seems like a generalization of another regression that
currently lives in the unresolvable_prefetch/ branch, but nobody had
to look at it yet. Your example will be added as a test, and all of
this will hopefully be fixed in a week or two. Until then the only
solution is to explicitly select the PK.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Peter Rabbitson-2

Re: breaking change ?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Gerrit Wichert
Gerrit Wichert wrote:

> hello,
>
> im using the following code  for quite some time (about a year) to get
> values of two related rows of the same table.
> This worked very well. But since the last upgrade of DBIx:_Class to
> version 0.08107 it failed with the following error:
>
> DBIx::Class::ResultSet::next(): Column id not loaded or not passed to
> new() prior to insert() on
> GS::Model::TimeControl::DBIx::TimeSheet=HASH(0x9707b0c) trying to
> resolve relationship (maybe you forgot to call ->discard_changes to get
> defaults from the db) at ...
>
> changing the select from:
>    select => [ qw/ me.login me.host me.type me.mtime end.mtime /],
> to
>    select => [ qw/ me.login me.host me.type me.mtime end.mtime me.id/],
> makes it work again.
> So is seems to fail when not including the primary key into the result.
>
> Is this really necessary to select the primary key?
> Is it a bug or a breaking change or can i write such requests in a
> better way?
>
>
> And btw. did anyone know of a db-portable way to deflate DateTime values
> in where statements?
>
> thanks,
>   Gerrit Wichert
>
>
>
>
>
> package GS::DBIC::Schemata::TimeControl::TimeSheet;
>
> use strict;
> use warnings;
>
> use base qw/DBIx::Class/;
>
> __PACKAGE__->load_components(qw/ InflateColumn::DateTime Core /);
> __PACKAGE__->table('time');
> __PACKAGE__->add_columns( qw/ id login type pid host /);
> __PACKAGE__->add_columns(  mtime =>{data_type =>'TIMESTAMP'},);
> __PACKAGE__->set_primary_key('id');
>
> __PACKAGE__->belongs_to(
>     'end',
>     __PACKAGE__,
>     {'foreign.pid'=>'self.id'},
>     {'join_type' => 'left'}
>     );
> 1;
>
>
>
> ...
> my $rs = $schema->resultset('TimeSheet')->
>           search( {'me.login' => $employeeId,
>                          'me.pid'   => {'=' => 0},
>                          'me.mtime' => {
>                                                     '>'  => $date->ymd,
>                                                     '<'  =>
> $date->clone->add(days=>1)->ymd
>                                                    }
>                         },
>                         { join   => [qw/ end /],        
>                           select => [ qw/ me.login me.host me.type
> me.mtime end.mtime /],
>                         });
>
> while (my $entry = $rs->next) {
> ...
> }  
>
>

This issue was finally fixed. Please try current trunk[1], and report
any problems.

Cheers

[1] http://dev.catalyst.perl.org/repos/bast/DBIx-Class/0.08/trunk/

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...