Skip Menu |
 

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

Report information
The Basics
Id: 85032
Status: new
Priority: 0/
Queue: DBIx-Class-Fixtures

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

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

Attachments
0002-Fixes-RT-37510-bug-lowercases-all-columns-before-dum.patch



CC: Mark Grimes <mgrimes [...] cpan.org>
Subject: [PATCH] Demonstrates uppercase column name bug by adding BARCODE to CD
Date: Fri, 3 May 2013 09:12:47 -0400
To: bug-DBIx-Class-Fixtures [...] rt.cpan.org
From: Mark Grimes <mgrimes [...] cpan.org>
Download (untitled) / with headers
text/plain 3.4k
The fixtures appear to be dumped correctly, but populate() failes when attempting to deploy the test database: DBIx::Class::Fixtures::populate(): No such column 'BARCODE' on source Cd at t/12-populate-basic.t line 31 --- t/lib/DBICTest.pm | 14 +++++++------- t/lib/DBICTest/Schema/CD.pm | 4 ++++ t/lib/DBICTest/Schema2/CD.pm | 4 ++++ t/lib/mysql.sql | 3 ++- t/lib/sqlite.sql | 3 ++- t/lib/sqlite_different.sql | 3 ++- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 988e02b..c7f0ebf 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -154,13 +154,13 @@ sub populate_schema { ]); $schema->populate('CD', [ - [ qw/cdid artist title year/ ], - [ 1, 1, "Spoonful of bees", 1999 ], - [ 2, 1, "Forkful of bees", 2001 ], - [ 3, 1, "Caterwaulin' Blues", 1997 ], - [ 4, 2, "Generic Manufactured Singles", 2001 ], - [ 5, 2, "We like girls and stuff", 2003 ], - [ 6, 3, "Come Be Depressed With Us", 1998 ], + [ qw/cdid artist title year BARCODE/ ], + [ 1, 1, "Spoonful of bees", 1999, 100 ], + [ 2, 1, "Forkful of bees", 2001, 200 ], + [ 3, 1, "Caterwaulin' Blues", 1997, 300 ], + [ 4, 2, "Generic Manufactured Singles", 2001, 400 ], + [ 5, 2, "We like girls and stuff", 2003, 500 ], + [ 6, 3, "Come Be Depressed With Us", 1998, 600 ], ]); $schema->populate('Tag', [ diff --git a/t/lib/DBICTest/Schema/CD.pm b/t/lib/DBICTest/Schema/CD.pm index a6f084f..f29d39f 100644 --- a/t/lib/DBICTest/Schema/CD.pm +++ b/t/lib/DBICTest/Schema/CD.pm @@ -20,6 +20,10 @@ __PACKAGE__->add_columns( data_type => 'varchar', size => 100, }, + 'BARCODE' => { + data_type => 'varchar', + size => 100, + }, ); __PACKAGE__->set_primary_key('cdid'); __PACKAGE__->add_unique_constraint([ qw/artist title/ ]); diff --git a/t/lib/DBICTest/Schema2/CD.pm b/t/lib/DBICTest/Schema2/CD.pm index 7d11ebc..1e8fc36 100644 --- a/t/lib/DBICTest/Schema2/CD.pm +++ b/t/lib/DBICTest/Schema2/CD.pm @@ -20,6 +20,10 @@ __PACKAGE__->add_columns( data_type => 'varchar', size => 100, }, + 'BARCODE' => { + data_type => 'varchar', + size => 100, + }, ); __PACKAGE__->set_primary_key('cdid'); __PACKAGE__->add_unique_constraint([ qw/artist title/ ]); diff --git a/t/lib/mysql.sql b/t/lib/mysql.sql index ca1b034..e8cb405 100644 --- a/t/lib/mysql.sql +++ b/t/lib/mysql.sql @@ -26,7 +26,8 @@ CREATE TABLE cd ( cdid INTEGER PRIMARY KEY NOT NULL, artist integer NOT NULL, title varchar(100) NOT NULL, - year varchar(100) NOT NULL + year varchar(100) NOT NULL, + BARCODE varchar(100) NOT NULL ); -- diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 1e21627..277d297 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -29,7 +29,8 @@ CREATE TABLE cd ( cdid INTEGER PRIMARY KEY NOT NULL, artist integer NOT NULL, title varchar(100) NOT NULL, - year varchar(100) NOT NULL + year varchar(100) NOT NULL, + BARCODE varchar(100) NOT NULL ); -- diff --git a/t/lib/sqlite_different.sql b/t/lib/sqlite_different.sql index 77b1de4..e53af3c 100644 --- a/t/lib/sqlite_different.sql +++ b/t/lib/sqlite_different.sql @@ -20,7 +20,8 @@ CREATE TABLE cd ( cdid INTEGER PRIMARY KEY NOT NULL, artist integer NOT NULL, title varchar(100) NOT NULL, - year varchar(100) NOT NULL + year varchar(100) NOT NULL, + BARCODE varchar(100) NOT NULL ); -- -- 1.8.2.1
The attached patch should fix the bug. -Mark
Subject: 0002-Fixes-RT-37510-bug-lowercases-all-columns-before-dum.patch
From e972c3cb96d60b2c2cdf41fe034ec36021749fb1 Mon Sep 17 00:00:00 2001 From: Mark Grimes <mgrimes@cpan.org> Date: Fri, 3 May 2013 17:38:25 -0400 Subject: [PATCH 2/2] Fixes RT#37510 bug: lowercases all columns before dumping fixtures DBIx::Class::ResultSet->populate wants all the keys lowercased. --- lib/DBIx/Class/Fixtures.pm | 14 +++++++++++++- t/03-dump-quantity.t | 3 ++- t/12-populate-basic.t | 3 ++- t/16-rules-hasmany.t | 3 ++- t/17-dump_all_config_sets.t | 3 ++- t/lib/DBICTest.pm | 18 ++++++++++++++++++ 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index 76f3de0..b103008 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -855,6 +855,17 @@ sub dump_object { $self->msg('-- dumping ' . $file->stringify, 2); my %ds = $object->get_columns; + # Converts all keys to lowercase b/c populate wants lowercased column + # names. Preserve original name in case we need to look up info via + # result_source->column_info, which wants the original casing. + my %orig_col_names; + for my $key ( keys %ds ) { + my $lowercase_key = lc $key; + $orig_col_names{$lowercase_key} = $key; + next if $lowercase_key eq $key; + $ds{ lc $key } = delete $ds{$key}; + } + if($set->{external}) { foreach my $field (keys %{$set->{external}}) { my $key = $ds{$field}; @@ -882,7 +893,8 @@ sub dump_object { } while (my ($col, $value) = each %ds) { - my $col_info = $object->result_source->column_info($col); + my $orig_col_name = $orig_col_names{$col}; + my $col_info = $object->result_source->column_info($orig_col_name); next unless $value && $col_info->{_inflate_info} diff --git a/t/03-dump-quantity.t b/t/03-dump-quantity.t index 011d0ee..239107c 100644 --- a/t/03-dump-quantity.t +++ b/t/03-dump-quantity.t @@ -25,5 +25,6 @@ foreach my $cd_fix_file (@children) { my $HASH1; eval($cd_fix_file->slurp()); is(ref $HASH1, 'HASH', 'fixture evals into hash'); my $cd = $schema->resultset('CD')->find($HASH1->{cdid}); - is_deeply({$cd->get_columns}, $HASH1, 'dumped fixture is equivalent to cd row'); + is_deeply( { DBICTest->lowercase_keys( $cd->get_columns ) }, + $HASH1, 'dumped fixture is equivalent to cd row' ); } diff --git a/t/12-populate-basic.t b/t/12-populate-basic.t index e37f490..023bc43 100644 --- a/t/12-populate-basic.t +++ b/t/12-populate-basic.t @@ -28,6 +28,7 @@ foreach my $set ('simple', 'quantity', 'fetch', 'rules') { directory => 't/var/fixtures' }), "$set dump executed okay" ); + $fixtures->populate({ ddl => 't/lib/sqlite.sql', connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''], @@ -52,7 +53,7 @@ foreach my $set ('simple', 'quantity', 'fetch', 'rules') { my $HASH1; eval($file->slurp()); is_deeply( $HASH1, - {$row->get_columns}, + { DBICTest->lowercase_keys( $row->get_columns ) }, "$set " . lc($class) . " row " . $row->id . " imported okay" ); } diff --git a/t/16-rules-hasmany.t b/t/16-rules-hasmany.t index 7014e4f..72f7667 100644 --- a/t/16-rules-hasmany.t +++ b/t/16-rules-hasmany.t @@ -30,7 +30,8 @@ foreach my $test ( my $HASH1; eval($fix_file->slurp()); is(ref $HASH1, 'HASH', 'fixture evals into hash'); my $obj = $schema->resultset($moniker)->find($HASH1->{$id}); - is_deeply({$obj->get_columns}, $HASH1, "dumped fixture is equivalent to $dirname row"); + is_deeply( { DBICTest->lowercase_keys( $obj->get_columns ) }, + $HASH1, "dumped fixture is equivalent to $dirname row" ); } } diff --git a/t/17-dump_all_config_sets.t b/t/17-dump_all_config_sets.t index 96d03da..9be0e32 100644 --- a/t/17-dump_all_config_sets.t +++ b/t/17-dump_all_config_sets.t @@ -36,7 +36,8 @@ is(ref $HASH1, 'HASH', 'fixture evals into hash'); is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys'); my $artist = $schema->resultset('Artist')->find($HASH1->{artistid}); -is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row'); +is_deeply( { DBICTest->lowercase_keys( $artist->get_columns ) }, + $HASH1, 'dumped fixture is equivalent to artist row' ); $schema->resultset('Artist')->delete; # so we can create the row again on the next line ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture'); diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index c7f0ebf..bcdb751 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -213,4 +213,22 @@ sub populate_schema { ]); } +=head2 lowercase_keys + + DBICTest->lowercase_keys( %hash ); + +Lowercases all the keys in the hash. Returns a hash. Does not check for +conflicts. + +=cut + +sub lowercase_keys { + my ($self, %hash) = @_; + + # Lowercase every odd (counting from 1) item; these are the hash keys + my $i = 0; + my %lowercased_hash = map { ++$i % 2 ? lc $_ : $_ } %hash; + return %lowercased_hash; +} + 1; -- 1.8.2.1


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

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.