Reduce to a warning the commit-without-apparent-begin exception from 7d216b10
Peter Rabbitson [Fri, 14 Jan 2011 12:07:50 +0000 (13:07 +0100)]
Changes
lib/DBIx/Class/Storage/DBI.pm

diff --git a/Changes b/Changes
index b675310..d130aad 100644 (file)
--- a/Changes
+++ b/Changes
@@ -6,7 +6,10 @@ Revision history for DBIx::Class
         - Switch to a warning when find() is invoked with both a 'key'
           argument and a NULL-containing condition to satisfy the named
           constraint. Previously (starting with 0.08124) an exception was
-          thrown.
+          thrown
+        - Switch to a warning when a commit is attempted with an out-of-sync
+          transaction_depth (someone issued a begin externally to DBIC).
+          Previously (starting with 0.08124) an exception was thrown
 
     * Fixes
         - Revert default selection to being lazy again (eagerness introduced
index 4e2d2b9..a986557 100644 (file)
@@ -1420,7 +1420,10 @@ sub _dbh_begin_work {
 
 sub txn_commit {
   my $self = shift;
-  if ($self->{transaction_depth} == 1) {
+  if (! $self->_dbh) {
+    $self->throw_exception('cannot COMMIT on a disconnected handle');
+  }
+  elsif ($self->{transaction_depth} == 1) {
     $self->debugobj->txn_commit()
       if ($self->debug);
     $self->_dbh_commit;
@@ -1432,6 +1435,17 @@ sub txn_commit {
     $self->svp_release
       if $self->auto_savepoint;
   }
+  elsif (! $self->_dbh->FETCH('AutoCommit') ) {
+
+    carp "Storage transaction_depth $self->{transaction_depth} does not match "
+        ."false AutoCommit of $self->{_dbh}, attempting COMMIT anyway";
+
+    $self->debugobj->txn_commit()
+      if ($self->debug);
+    $self->_dbh_commit;
+    $self->{transaction_depth} = 0
+      if $self->_dbh_autocommit;
+  }
   else {
     $self->throw_exception( 'Refusing to commit without a started transaction' );
   }