[Dbix-class] Why does this fail?

fREW Schmidt frioux at gmail.com
Wed Sep 30 18:16:14 GMT 2009


Hey guys,

So we have this search that only seems to work with searches of 3 characters
or less.  I am really at quite a loss as to what the deal is.  Here is the
code we are running that fails:

$user->subscription('FRIOUX')->limitations;
>
> Here are the result classes (User and Subscription) that the above is bas=
ed
on:

package CIS::Schema::Result::User;
> use base qw/DBIx::Class/;
> use strict;
> use warnings;
> use List::Util 'first';
>
> __PACKAGE__->load_components(qw/PK::Auto Core/);
> __PACKAGE__->table('User_Profile');
> __PACKAGE__->add_columns(qw/ user_id password address1 address2 city state
> zip
>    email phone fax date_joined first_name last_name country company_name
>    agreement commission_from message comment ext disable_logging
>    disable_accountedit edituser editdate trial chemfinet_userid
>    chemfinet_agreement enablesearchhelper /);
> __PACKAGE__->set_primary_key('user_id');
> __PACKAGE__->has_many('subscriptions' =3D>
> 'CIS::Schema::Result::Subscription',
>                         {'foreign.user_id' =3D> 'self.user_id'});
> __PACKAGE__->has_many('notes' =3D> 'CIS::Schema::Result::Note', 'user_id'=
);
> __PACKAGE__->has_many(searches =3D> 'CIS::Schema::Result::ActiveSearch',
>                       {'foreign.user_id' =3D> 'self.user_id'});


>
sub subscription {
>    my ($self, $prod) =3D @_;
>    # fails for $prod =3D qw{DWCP STRUCT WBDU WCMD SOURCE FRIOUX}
>    # works for $prod =3D qw{DMF PF WAY WES}
>    return $self->subscriptions->search({ 'me.product_name' =3D> $prod
> })->first;
>    # always works
>    # return first { $_->product_name eq $prod } $self->subscriptions->all;
> }



package CIS::Schema::Result::Subscription;
> use base qw/DBIx::Class/;
> use strict;
> use warnings;
>
> __PACKAGE__->load_components(qw/PK::Auto Core/);
> __PACKAGE__->table('User_Products');
>  __PACKAGE__->add_columns(qw/ user_id product_name user_type exp_date
> inst_left
>                          disable_renewal  mfg_id admin edituser editdate =
/,
>                          limitations =3D> {accessor =3D> '_limitations'});
>  __PACKAGE__->set_primary_key(qw/ user_id product_name /);
> __PACKAGE__->belongs_to('users' =3D> 'CIS::Schema::Result::User', 'user_i=
d');
> __PACKAGE__->might_have('manufacturer' =3D>
> 'CIS::Schema::Result::Manufacturer',
>                         {'foreign.mfg_id' =3D> 'self.mfg_id'} );
>

It turns out that DBI actually returns no results in the query.  Here's the
trace (long):

    DBI 1.607-ithread default trace level set to 0x0/1 (pid 6124) at
> Company.pm line 130 via Company.pm line 234
> SELECT me.user_id, me.product_name, me.user_type, me.exp_date,
> me.inst_left, me.disable_renewal, me.mfg_id, me.admin, me.edituser,
> me.editdate, me.limitations FROM User_Products me WHERE ( ( me.product_na=
me
> =3D ? AND me.user_id =3D ? ) ): 'FRIOUX', 'wesm'
>     <- prepare_cached('SELECT me.user_id, me.product_name, me.user_type,
> me.exp_date, me.inst_left, me.disable_renewal, me.mfg_id, me.admin,
> me.edituser, me.editdate, me.limitations FROM User_Products me WHERE ( (
> me.product_name =3D ? AND me.user_id =3D ? ) )', HASH(0x34f1b94), ...)=3D
> DBI::st=3DHASH(0x32bd12c) at DBI.pm line 1777
>     *<- bind_param(1, 'FRIOUX', ...)=3D 1 at DBI.pm line 1123**
>     <- bind_param(2, 'wesm', ...)=3D 1 at DBI.pm line 1123
>     <- execute=3D '0E0' at DBI.pm line 1129
>     <- fetchrow_array=3D ( ) [0 items] at Cursor.pm line 89*
>      <- FETCH('Active')=3D 1 at ADO.pm line 986
>     <- disconnect=3D 1 at ADO.pm line 986
>     <- DESTROY(DBI::db=3DHASH(32896ec))=3D undef at Dispatch.pm line 701
>     <- DESTROY(DBI::st=3DHASH(328991c))=3D undef at Dispatch.pm line 701
>     <- DESTROY(DBI::st=3DHASH(34fb85c))=3D undef at Dispatch.pm line 701
>     <- DESTROY(DBI::st=3DHASH(34f31f4))=3D undef at Dispatch.pm line 701
>     <- DESTROY(DBI::st=3DHASH(34fec1c))=3D undef at Dispatch.pm line 701
>      <- DESTROY(DBI::st=3DHASH(34f1d14))=3D undef at Dispatch.pm line 701
>     <- DESTROY(DBI::st=3DHASH(34fea5c))=3D undef at Dispatch.pm line 701
>     <- DESTROY(DBI::st=3DHASH(2705f84))=3D undef at Dispatch.pm line 701
>      <- FETCH('Active')=3D 1 at ADO.pm line 986
> <- disconnect=3D 1 at ADO.pm line 986
>     <- DESTROY(DBI::db=3DHASH(32bc0fc))=3D undef at Dispatch.pm line 701
> [Dispatch] ERROR for request
> '/cis/company/list/?dir=3DASC&sort=3Dline1&term=3Dfadgahgh&type=3DMatch%2=
0All%20Words':
> Error executing run mode 'list': Can't call method "limitations" on an
> undefined value at C:/Inetpub/gic/CIS/Controller/Company.pm line 132.
>
  at C:/Perl/site/lib/CGI/Application/Dispatch.pm line 704
>

Note the highlighted (if you can) section above.  You can also just search
for FRIOUX in the output to find it.  Zero rows returned.

The crazy thing is that it works fine with vanilla DBI:

   my $sth =3D $self->schema->storage->dbh->prepare(q{SELECT * FROM
> user_products WHERE user_id =3D ? AND product_name =3D ?});
>    $sth->execute('wesm', 'DWCP');
>    while (my $row =3D $sth->fetchrow_hashref) {
>       warn "TEST ROW YEAHHHH";
>       warn $row->{Product_Name};
>    }
>

Also, we can't seem to reproduce this in a test script, only in a mod_perl
environment...

Ideas?

-- =

fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090930/e35=
56752/attachment-0001.htm


More information about the DBIx-Class mailing list