From: Peter Rabbitson Date: Fri, 14 Jan 2011 12:07:50 +0000 (+0100) Subject: Reduce to a warning the commit-without-apparent-begin exception from 7d216b10 X-Git-Tag: v0.08127~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f107730c1bc2e5dc08f2990639aaf779cea4605d;p=dbsrgits%2FDBIx-Class.git Reduce to a warning the commit-without-apparent-begin exception from 7d216b10 --- diff --git a/Changes b/Changes index b675310..d130aad 100644 --- 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 diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 4e2d2b9..a986557 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -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' ); }