Fix endless loop on BareSourcelessResultClass->throw_exception(...)
Peter Rabbitson [Fri, 24 Oct 2014 23:35:14 +0000 (01:35 +0200)]
There is a better fix for this in the pipes, but this will do for now

(cherry pick of 4f52479b)

Changes
lib/DBIx/Class/Row.pm
t/60core.t
t/resultsource/bare_resultclass_exception.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index c663be3..7918191 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@ Revision history for DBIx::Class
     * Fixes
         - Fix incorrect collapsing-parser source being generated in the
           presence of unicode data among the collapse-points
+        - Fix endless loop on BareSourcelessResultClass->throw_exception(...)
 
     * Misc
         - Depend on newer Moo, fixing some interoperability issues:
index 2462b3b..190687c 100644 (file)
@@ -1565,8 +1565,8 @@ See L<DBIx::Class::Schema/throw_exception>.
 sub throw_exception {
   my $self=shift;
 
-  if (ref $self && ref $self->result_source ) {
-    $self->result_source->throw_exception(@_)
+  if (ref $self && ref (my $rsrc = try { $self->result_source_instance } ) ) {
+    $rsrc->throw_exception(@_)
   }
   else {
     DBIx::Class::Exception->throw(@_);
index f92159b..9ee9b6d 100644 (file)
@@ -636,4 +636,6 @@ SKIP: {
 
 throws_ok { $schema->resultset} qr/resultset\(\) expects a source name/, 'resultset with no argument throws exception';
 
+throws_ok { $schema->source('Artist')->result_class->new( 'bugger' ) } qr/must be a hashref/;
+
 done_testing;
diff --git a/t/resultsource/bare_resultclass_exception.t b/t/resultsource/bare_resultclass_exception.t
new file mode 100644 (file)
index 0000000..6b8d72c
--- /dev/null
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use lib 't/lib';
+use DBICTest;
+
+{
+  package DBICTest::Foo;
+  use base "DBIx::Class::Core";
+}
+
+throws_ok { DBICTest::Foo->new("urgh") } qr/must be a hashref/;
+
+done_testing;