discard changes now is forced to use master for replication. changed discard_changes...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / TxnScopeGuard.pm
index 04978f9..d699138 100644 (file)
@@ -1,4 +1,5 @@
-package DBIx::Class::Storage::TxnScopeGuard;
+package # Hide from pause for now - till we get it working
+  DBIx::Class::Storage::TxnScopeGuard;
 
 use strict;
 use warnings;
@@ -20,7 +21,23 @@ sub commit {
 sub DESTROY {
   my ($dismiss, $storage) = @{$_[0]};
 
-  $storage->txn_rollback unless $dismiss;
+  return if $dismiss;
+
+  my $exception = $@;
+
+  $DB::single = 1;
+
+  local $@;
+  eval { $storage->txn_rollback };
+  my $rollback_exception = $@;
+  if($rollback_exception) {
+    my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
+
+    $storage->throw_exception(
+      "Transaction aborted: ${exception}. "
+      . "Rollback failed: ${rollback_exception}"
+    ) unless $rollback_exception =~ /$exception_class/;
+  }
 }
 
 1;