FilterColumn deleting entries when set twice

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

FilterColumn deleting entries when set twice

Matthew Somerville
Hi,

The code I quote below gives the following output, 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.

The problem does not occur with DBIx::Class 0.08209, which I had
installed elsewhere; sorry I haven't had time to install the version
just prior to that commit to check. Hope that's helpful.

ATB,
Matthew

-----------------------------

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";

_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: FilterColumn deleting entries when set twice

Matthew Somerville
On 12 June 2015 at 14:11, Peter Rabbitson <[hidden email]> wrote:
> On 06/12/2015 01:11 AM, Matthew Somerville wrote:

>> ie. if you set a filtered column more than once before saving it, the
>> data is lost when saved.

> Problem confirmed. Will be addressed within a week.

Any update on this?

ATB,
Matthew

_______________________________________________
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@...