[Rt-commit] rt branch, 4.4/not-apply-scrip-batch-in-nested-atomic, created. rt-4.4.4-79-g49294ae81e

? sunnavy sunnavy at bestpractical.com
Tue Dec 3 15:33:42 EST 2019


The branch, 4.4/not-apply-scrip-batch-in-nested-atomic has been created
        at  49294ae81e86ae23fa46b7c0f75a83cc30b71f2c (commit)

- Log -----------------------------------------------------------------
commit 49294ae81e86ae23fa46b7c0f75a83cc30b71f2c
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Dec 4 04:07:09 2019 +0800

    Call ApplyTransactionBatch only in the most outer Atomic call
    
    Batch scrips are supposed to run at last, after all the user actions.
    Previously we called ApplyTransactionBatch in every Atomic call, which
    might cause batch scrips to run earlier than they are supposed to be,
    when there are nested Atomic calls involved.
    
    E.g. on ticket display page, we have all the Process... methods wrapped
    into an Atomic call, but one of the Process methods(ProcessTicketBasics)
    calls SetOwner that makes another Atomic call, which could cause
    ApplyTransactionBatch to run before other normal changes made by the
    following Process... methods including ProcessTicketLinks,
    ProcessTicketDates, ProcessObjectCustomFieldUpdates and
    ProcessTicketReminders, which is unexpected.

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 81224831cc..0156b4754b 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -1759,6 +1759,8 @@ ticket changes via the UI
 sub Atomic {
     my $self = shift;
     my ($subref) = @_;
+    $self->{Atomic}++;
+
     my $has_id = defined $self->id;
     $RT::Handle->BeginTransaction;
     my $depth = $RT::Handle->TransactionDepth;
@@ -1785,8 +1787,9 @@ sub Atomic {
     }
 
     if ($RT::Handle->TransactionDepth == $depth) {
-        $self->ApplyTransactionBatch;
+        $self->ApplyTransactionBatch if $self->{Atomic} == 1;
         $RT::Handle->Commit;
+        $self->{Atomic}--;
     }
 
     return $context ? @ret : $ret[0];

-----------------------------------------------------------------------


More information about the rt-commit mailing list