[Catalyst-commits] r12657 - in CatalystX-CRUD/CatalystX-CRUD/trunk:
. lib/CatalystX/CRUD t t/lib/MyApp/Controller
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Fri Jan 15 07:03:32 GMT 2010
Author: karpet
Date: 2010-01-15 07:03:31 +0000 (Fri, 15 Jan 2010)
New Revision: 12657
Added:
CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t
CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapterMultiPK.pm
Modified:
CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapter.pm
Log:
fix bug with multicolumn PKs reported by Adam Mackler
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/Changes 2010-01-15 06:35:30 UTC (rev 12656)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/Changes 2010-01-15 07:03:31 UTC (rev 12657)
@@ -229,4 +229,6 @@
0.47 xxx
* fix tutorial per RT#53396
-
+ * fix bug in base Controller->fetch() where multiple PKs where one value is null were slipping
+ through. Reported by Adam Mackler.
+
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2010-01-15 06:35:30 UTC (rev 12656)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2010-01-15 07:03:31 UTC (rev 12657)
@@ -143,7 +143,25 @@
my ( $self, $c, $id ) = @_;
$c->stash->{object_id} = $id;
my @pk = $self->get_primary_key( $c, $id );
- my @arg = $id ? (@pk) : ();
+
+ # make sure all elements of the @pk pairs are not-null
+ if ( scalar(@pk) % 2 ) {
+ $self->throw_error(
+ "Odd number of elements returned from get_primary_key()");
+ }
+ my %pk_pairs = @pk;
+ my $pk_is_null;
+ for my $key ( keys %pk_pairs ) {
+ my $val = $pk_pairs{$key};
+ if ( !defined($val) or !length($val) ) {
+ $pk_is_null = $key;
+ last;
+ }
+ }
+ if ( $c->debug and defined $pk_is_null ) {
+ $c->log->debug("Null PK value for '$pk_is_null'");
+ }
+ my @arg = defined $pk_is_null ? () : (@pk);
$c->log->debug( "fetch: " . dump \@arg ) if $c->debug;
$c->stash->{object} = $self->do_model( $c, 'fetch', @arg );
if ( $self->has_errors($c) or !$c->stash->{object} ) {
Added: CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/t/05-pks.t 2010-01-15 07:03:31 UTC (rev 12657)
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use Test::More tests => 2;
+use lib qw( lib t/lib );
+use Catalyst::Test 'MyApp';
+use Data::Dump qw( dump );
+use HTTP::Request::Common;
+
+my $res;
+ok( $res = request(
+ HTTP::Request->new( GET => '/fileadaptermultipk/testfile;;/read' )
+ ),
+ "GET new file with null pk"
+);
+
+is( $res->headers->{status}, 500, "exception thrown" );
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/File.pm 2010-01-15 06:35:30 UTC (rev 12656)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/File.pm 2010-01-15 07:03:31 UTC (rev 12657)
@@ -7,7 +7,6 @@
use MyApp::Form;
__PACKAGE__->config(
- primary_key => 'absolute',
form_class => 'MyApp::Form',
form_fields => [qw( file content )],
model_name => 'File',
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapter.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapter.pm 2010-01-15 06:35:30 UTC (rev 12656)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapter.pm 2010-01-15 07:03:31 UTC (rev 12657)
@@ -7,7 +7,6 @@
use MyApp::Form;
__PACKAGE__->config(
- primary_key => 'absolute',
form_class => 'MyApp::Form',
form_fields => [qw( file content )],
model_adapter => 'CatalystX::CRUD::ModelAdapter::File',
Added: CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapterMultiPK.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapterMultiPK.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/t/lib/MyApp/Controller/FileAdapterMultiPK.pm 2010-01-15 07:03:31 UTC (rev 12657)
@@ -0,0 +1,19 @@
+package MyApp::Controller::FileAdapterMultiPK;
+use strict;
+use base qw( CatalystX::CRUD::Test::Controller );
+use Carp;
+use Data::Dump qw( dump );
+use File::Temp;
+use MyApp::Form;
+
+__PACKAGE__->config(
+ primary_key => [qw( file foo bar )],
+ form_class => 'MyApp::Form',
+ form_fields => [qw( file content )],
+ model_adapter => 'CatalystX::CRUD::ModelAdapter::File',
+ model_name => 'File',
+ init_form => 'init_with_file',
+ init_object => 'file_from_form',
+);
+
+1;
More information about the Catalyst-commits
mailing list