[Dbix-class] CDBICompat NumExplodingSheep

Dave Howorth dhoworth at mrc-lmb.cam.ac.uk
Tue Nov 18 17:16:16 GMT 2008


I think there are some problems in test t/cdbi-t/15-accessor-new.t

=============

I think there's a latent bug after line 53:

my $data = {
    Title    => 'Bad Taste',
    Director => 'Peter Jackson',
    Rating   => 'R',
};

eval {
    my $data = $data;
    $data->{NumExplodingSheep} = 1;
    ok my $bt = Film->create($data), "Modified accessor - with column name";
    isa_ok $bt, "Film";
};
is $@, '', "No errors";

eval {
    my $data = $data;
    $data->{sheep} = 1;
    ok my $bt = Film->create($data), "Modified accessor - with accessor";
    isa_ok $bt, "Film";
};
is $@, '', "No errors";

The problem is that in the second eval $data->{NumExplodingSheep} still
has the value 1 [the lovely tricky assignment is only doing a top-level
copy, so the value from the first eval was copied into the top-level
lexical and made available in the second eval]. So that test isn't
really a fair test of what it claims to be testing.

Luckily, the test still passes after hacking in a:
  delete $data->{NumExplodingSheep};
which is good news. I expect something like my $data = { %$data }; might
be better, or even using different variable names.

=============

I think there's an actual problem with "Can search with modified
accessor". Namely, there is no
  is $@, '', "No errors";
after the eval. After adding one, I see this output:


not ok 17 - No errors
#   Failed test 'No errors'
#   at ../15-accessor-new.t line 108.
#          got: 'DBIx::Class::CDBICompat::HasA::search(): DBI Exception:
DBD::SQLite::db prepare_cached failed: no such column: sheep(1) at
dbdimp.c line 271 [for Statement "SELECT me.title FROM Movies me WHERE (
sheep = ? )"] at ../15-accessor-new.t line 104
# '
#     expected: ''

(line and test numbers are not quite right because of other things I
changed above)

So AFAICT, search() does NOT work.

=============

I also think there's a problem with find_or_create() and accessor_for().
For starters there're no tests! But I haven't yet got a set of tests for
which I understand the results and which agree with the failure I'm
seeing in my application. They're similar to the one for search()  I'll
post some tests when I have them.

=============

More generally, the description of DBIx::Class::CDBICompat says
"DBIx::Class features a fully featured compatibility layer with
Class::DBI" and there's an impressively short list of limitations. I'm
beginning to have doubts about that description - has anybody used this
stuff?

Cheers, Dave



More information about the DBIx-Class mailing list