Skip Menu |

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

Report information
The Basics
Id: 95054
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: ALEXBYK [...] cpan.org
Cc:
AdminCc:

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



Subject: filter_column + 2 * find_or_create always dies if column is uniq
I have a filter like below for some uniq column (pls see a full test in attached file) # sub to_storage { $_[1] * 100 } # sub from_storage { $_[1] / 100 } $schema->resultset('Item')->find_or_create({id => 1}); $schema->resultset('Item')->find_or_create({id => 1}); That code will die at the 2'nd line because find_or_create doesn't respect a filter and generated SQL will be wrong # must be '100', not '1' SELECT me.id FROM items me WHERE ( me.id = ? ): '1' INSERT INTO items ( id) VALUES ( ? ): '100'
Subject: dbic-test.log
SELECT me.id FROM items me WHERE ( me.id = ? ): '3' INSERT INTO items ( id) VALUES ( ? ): '300' SELECT me.id FROM items me WHERE ( me.id = ? ): '3' INSERT INTO items ( id) VALUES ( ? ): '300' # Failed test 'find_or_create must return a true value' # at t/model/item.t line 45. SELECT me.id FROM items me WHERE ( me.id = ? ): '3' # Failed test 'we've just created id 3 on test above' # at t/model/item.t line 50. # Looks like you failed 2 tests of 3. t/model/item.t .. ok 1 - ID must transform twice (3->300->3) not ok 2 - find_or_create must return a true value not ok 3 - we've just created id 3 on test above 1..3 Dubious, test returned 2 (wstat 512, 0x200) Failed 2/3 subtests
Subject: dbix-bug.t
# In Item.pm # ... # __PACKAGE__->load_components("FilterColumn"); # __PACKAGE__->table("items"); # __PACKAGE__->add_columns( # "id", # { # data_type => "integer", # extra => {unsigned => 1}, # is_auto_increment => 1, # is_nullable => 0, # }, # ); # __PACKAGE__->set_primary_key("id"); # # __PACKAGE__->filter_column( # id => { # filter_to_storage => 'to_storage', # filter_from_storage => 'from_storage', # } # ); # # sub to_storage { $_[1] * 100 } # sub from_storage { $_[1] / 100 } # the_test.t # ... init code is omitted $schema->resultset('Item')->delete_all; # 1) DOESN'T WORK # we're going to insert id 3 and find it after that my $id_3 = 3; my $item = $schema->resultset('Item')->find_or_create({id => $id_3}); is $item->id, $id_3, "ID must transform twice ($id_3->300->$id_3)"; # dies ! ok eval { $schema->resultset('Item')->find_or_create({id => $id_3}) }, "find_or_create must return a true value"; CHECK_ID_3: { my $item = $schema->resultset('Item')->find({id => $id_3}); ok $item && $item->id == $id_3, "we've just created id 3 on test above"; } # 2) WORKS GREAT only this way # this way it works # subtest id_4 => sub { # $schema->storage->debug(0); # my $id_4 = 4; # my $item = $schema->resultset('Item')->new({id => $id_4}); # # $item->insert; # # my $check = $schema->resultset('Item')->new({}); # $check->id($id_4); # ok $check->get_from_storage; # }; done_testing;
On Fri Apr 25 23:31:03 2014, ALEXBYK wrote: Show quoted text
> I have a filter like below for some uniq column (pls see a full test > in attached file) > # sub to_storage { $_[1] * 100 } > # sub from_storage { $_[1] / 100 } > > $schema->resultset('Item')->find_or_create({id => 1}); $schema-
> >resultset('Item')->find_or_create({id => 1});
filter_column affects object inflation/deflation only; applying it to the primary key would seem to be an error. Basically, this is a limitation of the model FilterColumn uses rather than a bug, and can't easily be changed at this time.
On Sat Apr 26 05:31:03 2014, ALEXBYK wrote: Show quoted text
> > That code will die at the 2'nd line because find_or_create doesn't > respect a filter and generated SQL will be wrong >
This is correct and as Matt pointed out earlier isn't fixable (due to how FilterColumn works). However DBIC now will correctly detect this and throw an exception as of https://github.com/dbsrgits/dbix-class/commit/7ed4b48f To my fellow comaints - please do not reject tickets with "don't do that" "resolutions". This isn't a CADT[1] compliant project. Cheers [1] http://www.jwz.org/doc/cadt.html
Proper exception added in DBIC 0.082801: https://metacpan.org/release/RIBASUSHI/DBIx-Class-0.082801#whatsnew Cheers