From 494a63f9e81c2255de162ec5daad1fb2f28dc67b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 14 Dec 2022 08:42:03 +0100 Subject: [PATCH] Bug 32442: (bug 28739 follow-up) Ensure txn is rollbacked If the TT process call is returning false and so the croak is raised, then the txn is not rollbacked and the txn is not commited either. We need to ensure the txn will be correctly rollbacked. Test plan: 1. Go to any notice and create some invalid Template Toolkit: [% IF ( 1 == 1 %] test [% END %] 2. Save and continue 3. Logout of Koha and attempt to log back in => Without this patch you got Transaction aborted: DBIx::Class::Storage::DBI::mysql::_exec_svp_release(): DBI Exception: DBD::mysql::db do failed: SAVEPOINT savepoint_4 does not exist at /kohadevbox/koha/Koha/Object.pm line 170 . Rollback failed: DBIx::Class::Storage::DBI::mysql::_exec_svp_rollback(): DBI Exception: DBD::mysql::db do failed: SAVEPOINT savepoint_3 does not exist at /kohadevbox/koha/Koha/Patron.pm line 363 at /kohadevbox/koha/Koha/Patron.pm line 363 at /usr/share/perl5/DBIx/Class/Exception.pm line 77 => With this patch applied the login works successfully QA Note: The test is not testing that the txn is rolledback, I didn't manage to test that. Signed-off-by: Nick Clemens Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/Letters.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 4d60753cc6..3bddc69ecb 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -23,7 +23,7 @@ use Carp qw( carp croak ); use Template; use Module::Load::Conditional qw( can_load ); -use Try::Tiny qw( catch try ); +use Try::Tiny; use C4::Members; use C4::Log qw( logaction ); @@ -1620,8 +1620,13 @@ sub _process_tt { my $output; my $schema = Koha::Database->new->schema; $schema->txn_begin; - $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); - $schema->txn_rollback; + my $processed = try { + $template->process( \$content, $tt_params, \$output ); + } + finally { + $schema->txn_rollback; + }; + croak "ERROR PROCESSING TEMPLATE: " . $template->error() unless $processed; return $output; } -- 2.39.5