[Dbix-class] transaction depth not reset in 0.08003

Richard Jolly Richard.Jolly at bbc.co.uk
Wed Jul 18 18:40:31 GMT 2007


Hi,

We've just been trying upgrading to 0.08003 from 0.07000. Mostly fine,
but one problem with transactions. If a transaction fails the
transaction depth is not reset. The end result is that if you have two
failing transactions in a row, the second is actually not in a
transaction.

Here is a patch to t/81transactions.t to show the problem. I've looked
at the code, but I'm nowhere near familiar with it enough to offer a
fix.

[jollyr01 at ops-dev-pips DBIC-8.03]$ diff -u t/81transactions.t-orig
t/81transactions.t
--- t/81transactions.t-orig     Wed Jul 18 18:06:42 2007
+++ t/81transactions.t  Wed Jul 18 18:12:38 2007
@@ -7,7 +7,7 @@

 my $schema = DBICTest->init_schema();

-plan tests => 40;
+plan tests => 44;

 my $code = sub {
   my ($artist, @cd_titles) = @_;
@@ -95,6 +95,7 @@

 # Test failed txn_do()
 {
+
   my $artist = $schema->resultset('Artist')->find(3);

   eval {
@@ -109,8 +110,30 @@
     year => 2005,
   })->first;
   ok(!defined($cd), q{failed txn_do didn't change the cds table});
+
+  is( $schema->storage->{transaction_depth}, 0, 'txn depth has been
reset');
 }

+# do the same transaction again
+{
+  my $artist = $schema->resultset('Artist')->find(3);
+
+  eval {
+    $schema->txn_do($fail_code, $artist);
+  };
+
+  my $error = $@;
+
+  like($error, qr/the sky is falling/, 'failed txn_do threw an
exception');
+  my $cd = $artist->cds({
+    title => 'this should not exist',
+    year => 2005,
+  })->first;
+  ok(!defined($cd), q{failed txn_do didn't change the cds table});
+
+  is( $schema->storage->{transaction_depth}, 0, 'txn depth at 0');
+}
+
 # Test failed txn_do() with failed rollback
 {
   my $artist = $schema->resultset('Artist')->find(3);



And the output (including core dump):

[jollyr01 at ops-dev-pips DBIC-8.03]$ prove t/81transactions.t
t/81transactions....NOK 29/44
#   Failed test 'txn depth has been reset'
#   at t/81transactions.t line 114.
#          got: '1'
#     expected: '0'

#   Failed test 'failed txn_do didn't change the cds table'
t/81transactions....NOK 31/44#   at t/81transactions.t line 132.

#   Failed test 'txn depth at 0'
#   at t/81transactions.t line 134.
t/81transactions....NOK 32/44#          got: '1'
#     expected: '0'

#   Failed test 'failed txn_do with a failed txn_rollback included the
original exception'
t/81transactions....NOK 34/44#   at t/81transactions.t line 154.
#                   'DBIx::Class::Schema::txn_do(): Transaction aborted:
DBIx::Class::Relationship::Base::create_related(): DBI Exception:
DBD::SQLite::st execute failed: columns artist, title are not unique(1)
at dbdimp.c line 402 [for Statement "INSERT INTO cd (artist, title,
year) VALUES (?, ?, ?)"] at t/81transactions.t line 89
# . Rollback failed: FAILED at t/81transactions.t line 144.
# '
#     doesn't match '(?-xism:the sky is falling)'
t/81transactions....dubious
        Test returned status 0 (wstat 139, 0x8b)
DIED. FAILED tests 29, 31-32, 34, 37-44
        Failed 12/44 tests, 72.73% okay
Failed Test        Stat Wstat Total Fail  List of Failed
------------------------------------------------------------------------
-------
t/81transactions.t    0   139    44   20  29 31-32 34 37-44
Failed 1/1 test scripts. 12/44 subtests failed.
Files=1, Tests=44,  2 wallclock secs ( 0.51 cusr +  0.17 csys =  0.68
CPU)
Failed 1/1 test programs. 12/44 subtests failed.


Thanks,

Richard

http://www.bbc.co.uk/
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
					



More information about the Dbix-class mailing list