Skip Menu |

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

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

Owner: Nobody in particular
Requestors: radu [...]

Bug Information
Severity: Normal
Broken in: 0.08010
Fixed in: (no value)

Subject: UTF8 columns may be marked as dirty when they have not been really changed
Download (untitled) / with headers
text/plain 807b
I found that some columns are changed by an UPDATE statement even if the value used in set_column() is the same as the one read from the database. Also, UPDATEs are sent to the database even if I call update() with the values read from the database. In other words, in some cases something like $row->column( $row->column() ) caused the column to be marked as dirty. I found that the columns that were unnecessarily updated were UTF8Columns, containing non-latin1 characters. I traced this to the set_column method from DBIx::Class::Row, where a string of characters, $old, is compared with a string of bytes, $ret. In the case of non-latin1 characters $old and $ret are not equal. Attached is a test added to t85utf.t to show the problem. My version of perl is 5.8.5 and DBIx::Class is version 0.08010.
Subject: t85utf.t.diff
Download t85utf.t.diff
text/x-diff 735b
--- DBIx-Class-0.08010/t/85utf8.t.orig 2007-08-12 00:07:59.000000000 +0300 +++ DBIx-Class-0.08010/t/85utf8.t 2008-09-20 22:55:14.000000000 +0300 @@ -16,7 +16,7 @@ eval 'use utf8; 1' or plan skip_all => 'Need utf8 run this test'; } -plan tests => 3; +plan tests => 4; DBICTest::Schema::CD->load_components('UTF8Columns'); DBICTest::Schema::CD->utf8_columns('title'); @@ -43,3 +43,9 @@ $cd->title($utf8_char); ok( !utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' ); } + +my $v = "\x{219}"; # s with comma below (characters outside latin1 are needed) +$cd->title($v); +$cd->update; +$cd->title($v); +ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same value' );
From: radu [...]
Download (untitled) / with headers
text/plain 120b
I'm attaching a patch to solve my problem and make the test pass. It forces the UTF8 flag on the return of store_column.
--- DBIx-Class-0.08010/lib/DBIx/Class/ 2007-08-12 00:07:58.000000000 +0300 +++ DBIx-Class-0.08010/lib/DBIx/Class/ 2008-10-08 20:26:51.000000000 +0300 @@ -117,7 +117,18 @@ } } - $self->next::method( $column, $value ); + my $ret = $self->next::method( $column, $value ); + + if ( $cols and defined $ret and $cols->{$column} ) { + + if ($] <= 5.008000) { + Encode::_utf8_on($ret) unless Encode::is_utf8($ret); + } else { + utf8::decode($ret) unless utf8::is_utf8($ret); + } + } + + $ret; } =head1 AUTHOR
Subject: UTF8 columns may be marked as dirty when they have not been really changed [TEST/PATCH]
From: radu [...]
Updated subject.
Download (untitled) / with headers
text/plain 107b
The root cause of the problem has been fixed by

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to