From: Cory G Watson Date: Tue, 19 Jun 2007 21:07:39 +0000 (+0000) Subject: Call ensure_connected in txn_begin to avoid stomping on the transaction depth X-Git-Tag: v0.08010~146 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=291bf95f152ff0e9008d67f9d80310b2c6111fdd;p=dbsrgits%2FDBIx-Class.git Call ensure_connected in txn_begin to avoid stomping on the transaction depth --- diff --git a/Changes b/Changes index a6dca8f..e82e213 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - ensure_connected before txn_begin to catch stomping on transaction + depth - new method "rethrow" for our exception objects 0.08001 2007-06-17 21:21:02 diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 7d1ced1..7251ccf 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -788,6 +788,7 @@ sub _connect { sub txn_begin { my $self = shift; + $self->ensure_connected(); if($self->{transaction_depth}++ == 0) { $self->debugobj->txn_begin() if $self->debug; diff --git a/t/81transactions.t b/t/81transactions.t index 4a7830f..e16ff2b 100644 --- a/t/81transactions.t +++ b/t/81transactions.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 39; +plan tests => 40; my $code = sub { my ($artist, @cd_titles) = @_; @@ -178,3 +178,13 @@ my $fail_code = sub { ok(!defined($cd), q{failed txn_do didn't add failed txn's cd}); } +# Grab a new schema to test txn before connect +{ + my $schema2 = DBICTest->init_schema(no_deploy => 1); + eval { + $schema2->txn_begin(); + $schema2->txn_begin(); + }; + my $err = $@; + ok(($err eq ''), 'Pre-connection nested transactions.'); +}