Skip Menu |

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

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

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

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



Subject: FilterColumn deleting entries when set twice
As explained on the mailing list at http://lists.scsys.co.uk/pipermail/dbix-class/2015-June/012057.html but I wasn't sure if a ticket should be filed here too. Code for a minimal test case is given below. It outputs, with DBIx::Class 0.082820: Extra is: 123 Local object extra is: 456 Refetched extra is: 456 Local object extra is: 101112 Use of uninitialized value $n in multiplication (*) at test.pl line 16. Refetched extra is: 0 ie. if you set a filtered column more than once before saving it, the data is lost when saved. I'm not entirely sure, but this appears to be due to the change made in https://github.com/dbsrgits/dbix-class/commit/dc6dadae6 where set_filtered_column deletes the data if the column is already marked as changed. $ echo "create table problem (id integer primary key, extra text);" | sqlite3 test.db ----------------------------- package DB::Problem; use strict; use warnings; use DBIx::Class::FilterColumn; use base 'DBIx::Class::Core'; __PACKAGE__->load_components("FilterColumn"); __PACKAGE__->table("problem"); __PACKAGE__->add_columns( "id", { data_type => "integer" }, "extra", { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->filter_column( 'extra' => { filter_from_storage => sub { my ($self, $n) = @_; return $n * 2; }, filter_to_storage => sub { my ($self, $n) = @_; return $n / 2; }, } ); package DB; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_classes(qw(Problem)); package main; use Data::Dumper; my $schema = DB->connect('dbi:SQLite:test.db'); # Create an object $schema->resultset('Problem')->delete_all; $schema->resultset('Problem')->create({extra => 123}); my $p = $schema->resultset('Problem')->single; print "Extra is: ", $p->extra, "\n"; # Update it once $p->extra(456); print "Local object extra is: ", $p->extra, "\n"; $p->update; $p = $schema->resultset('Problem')->single; print "Refetched extra is: ", $p->extra, "\n"; # Update it twice $p->extra(789); $p->extra(101112); print "Local object extra is: ", $p->extra, "\n"; $p->update; $p = $schema->resultset('Problem')->single; print "Refetched extra is: ", $p->extra, "\n";
Subject: Re: [rt.cpan.org #111567] FilterColumn deleting entries when set twice
Date: Sat, 30 Jan 2016 12:19:52 +0100
To: bug-DBIx-Class [...] rt.cpan.org
From: Peter Rabbitson <ribasushi [...] cpan.org>
On 01/30/2016 12:11 PM, mySociety via RT wrote: Show quoted text
> Sat Jan 30 06:11:14 2016: Request 111567 was acted upon. > Transaction: Ticket created by MYSOCIETY > Queue: DBIx-Class > Subject: FilterColumn deleting entries when set twice > Broken in: 0.082820 > Severity: (no value) > Owner: Nobody > Requestors: MYSOCIETY@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=111567 > > > > As explained on the mailing list at http://lists.scsys.co.uk/pipermail/dbix-class/2015-June/012057.html but I wasn't sure if a ticket should be filed here too. Code for a minimal test case is given below. It outputs, with DBIx::Class 0.082820: > Extra is: 123 > Local object extra is: 456 > Refetched extra is: 456 > Local object extra is: 101112 > Use of uninitialized value $n in multiplication (*) at test.pl line 16. > Refetched extra is: 0 > > ie. if you set a filtered column more than once before saving it, the data is lost when saved. I'm not entirely sure, but this appears to be due to the change made in https://github.com/dbsrgits/dbix-class/commit/dc6dadae6 where set_filtered_column deletes the data if the column is already marked as changed.
This is still on my radar. Sorry for the delay in addressing this, and thanks for filing a placeholder so it doesn't get dropped. More news some time next week, once the other part of the txn clusterfuck lands.
On Sat Jan 30 12:11:14 2016, MYSOCIETY wrote: Show quoted text
> As explained on the mailing list at > http://lists.scsys.co.uk/pipermail/dbix-class/2015-June/012057.html > but I wasn't sure if a ticket should be filed here too. > ie. if you set a filtered column more than once before saving it, the > data is lost when saved.
This is now fixed by https://github.com/dbsrgits/dbix-class/commit/b482a095. Apologies for taking so long on this: the changeset is deceptively simple, as is everything around this ill-fated never-should-have-been-merged component :/
The fix is now properly in the CPAN index. Sorry it took so long :/