[Bast-commits] r7632 - in DBIx-Class/0.08/trunk: examples/Schema
lib/DBIx/Class/Storage t
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Fri Sep 11 22:44:01 GMT 2009
Author: ribasushi
Date: 2009-09-11 22:44:01 +0000 (Fri, 11 Sep 2009)
New Revision: 7632
Modified:
DBIx-Class/0.08/trunk/examples/Schema/insertdb.pl
DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/TxnScopeGuard.pm
DBIx-Class/0.08/trunk/t/81transactions.t
Log:
This is how the txnguard should really work
Modified: DBIx-Class/0.08/trunk/examples/Schema/insertdb.pl
===================================================================
--- DBIx-Class/0.08/trunk/examples/Schema/insertdb.pl 2009-09-11 22:15:50 UTC (rev 7631)
+++ DBIx-Class/0.08/trunk/examples/Schema/insertdb.pl 2009-09-11 22:44:01 UTC (rev 7632)
@@ -23,10 +23,10 @@
my @cds;
foreach my $lp (keys %albums) {
- my $artist = $schema->resultset('Artist')->search({
+ my $artist = $schema->resultset('Artist')->find({
name => $albums{$lp}
});
- push @cds, [$lp, $artist->first];
+ push @cds, [$lp, $artist->id];
}
$schema->populate('Cd', [
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/TxnScopeGuard.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/TxnScopeGuard.pm 2009-09-11 22:15:50 UTC (rev 7631)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/TxnScopeGuard.pm 2009-09-11 22:44:01 UTC (rev 7632)
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Carp ();
+use Carp::Clan qw/^DBIx::Class/;
sub new {
my ($class, $storage) = @_;
@@ -24,7 +24,8 @@
return if $dismiss;
my $exception = $@;
- Carp::cluck("A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or an error - bad")
+
+ carp 'A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error - bad'
unless $exception;
my $rollback_exception;
@@ -33,11 +34,15 @@
eval { $storage->txn_rollback };
$rollback_exception = $@;
}
+
if ($rollback_exception && $rollback_exception !~ /DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION/) {
- $storage->throw_exception(
- "Transaction aborted: ${exception} "
- . "Rollback failed: ${rollback_exception}"
- );
+ if ($exception) {
+ $@ = "Transaction aborted: ${exception} "
+ ."Rollback failed: ${rollback_exception}";
+ }
+ else {
+ carp "Rollback failed: ${rollback_exception}";
+ }
}
}
Modified: DBIx-Class/0.08/trunk/t/81transactions.t
===================================================================
--- DBIx-Class/0.08/trunk/t/81transactions.t 2009-09-11 22:15:50 UTC (rev 7631)
+++ DBIx-Class/0.08/trunk/t/81transactions.t 2009-09-11 22:44:01 UTC (rev 7632)
@@ -276,7 +276,7 @@
# The 0 arg says don't die, just let the scope guard go out of scope
# forcing a txn_rollback to happen
outer($schema, 0);
- }, qr/A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or an error/, 'Out of scope warning detected');
+ }, qr/A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error/, 'Out of scope warning detected');
ok(!$artist_rs->find({name => 'Death Cab for Cutie'}), "Artist not created");
}, 'rollback successful withot exception');
@@ -329,4 +329,21 @@
}, qr/Deliberate exception.+Rollback failed/s);
}
+# make sure it simply warns on failed rollbacks
+{
+ my $schema = DBICTest->init_schema();
+ warnings_exist (sub {
+ my $guard = $schema->txn_scope_guard;
+ $schema->resultset ('Artist')->create ({ name => 'bohhoo'});
+
+ $schema->storage->disconnect; # this should freak out the guard rollback
+
+ },
+ [
+ qr/A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error/,
+ qr/Rollback failed/,
+ ],
+ 'out-of-scope with failed rollback properly warned');
+}
+
done_testing;
More information about the Bast-commits
mailing list