Skip to content

Commit 49b6dab

Browse files
committed
Fail cleanly when a scrip aborts the transaction with a database error
Custom scrips can contain code that causes deadlocks, potentially leading to the failure of an entire database operation. However, when the automatic rollback occurs, RT may have already returned a false success. For example, if a scrip that runs on ticket create causes deadlocks, the system may display a "ticket created" message, but it's a ghost ticket as it doesn't actually exist in database.
1 parent 01397ed commit 49b6dab

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

etc/cpanfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ requires 'DateTime::Format::Natural', '>= 0.67';
2525
requires 'DateTime::Locale', '>= 0.40, != 1.00, != 1.01';
2626
requires 'DateTime::Set';
2727
requires 'DBI', '>= 1.37';
28-
requires 'DBIx::SearchBuilder', '>= 1.85';
28+
requires 'DBIx::SearchBuilder', '>= 1.86';
2929
requires 'Devel::GlobalDestruction';
3030
requires 'Devel::StackTrace', '>= 1.19, != 1.28, != 1.29';
3131
requires 'Digest::base';

lib/RT/Transaction.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ sub Create {
303303
RT::Ruleset->CommitRules($rules);
304304
}
305305

306+
# An aborted transaction is rolled back at Commit, so don't return an id for it.
307+
if ( RT->DatabaseHandle->TransactionAborted ) {
308+
return ( 0, $self->loc("Transaction could not be created; the database transaction was aborted") );
309+
}
310+
306311
return @return;
307312
}
308313

0 commit comments

Comments
 (0)