[Rt-commit] rt branch, 4.4/only-warn-once-about-unsafe-scrips-in-global-destruction, created. rt-4.4.4-144-gba69065982

Dianne Skoll dianne at bestpractical.com
Fri Oct 2 08:57:09 EDT 2020


The branch, 4.4/only-warn-once-about-unsafe-scrips-in-global-destruction has been created
        at  ba690659821488b78a9bcb494ea7cfdaa9a77963 (commit)

- Log -----------------------------------------------------------------
commit ba690659821488b78a9bcb494ea7cfdaa9a77963
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Tue Sep 22 16:23:58 2020 -0400

    Issue the "Too late to safely run transaction-batch scrips!" warning at most once.
    
    If it's issued dozens/hundreds/thousands of times, it could hide the real
    error if invoked from a command-line script whose output is not captured.
    
    (Note, however, that if DevelMode is configured, we do not suppress
    repeated warnings.)

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 81224831cc..f9cc42ddf2 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -67,6 +67,7 @@ package RT::Ticket;
 
 use strict;
 use warnings;
+use 5.10.1;
 use base 'RT::Record';
 
 use Role::Basic 'with';
@@ -2732,6 +2733,7 @@ sub _ApplyTransactionBatch {
 }
 
 sub DESTROY {
+    state $warned = 0;
     my $self = shift;
 
     # DESTROY methods need to localize $@, or it may unset it.  This
@@ -2745,12 +2747,16 @@ sub DESTROY {
     return if $self->{_Destroyed}++;
 
     if (in_global_destruction()) {
-       unless ($ENV{'HARNESS_ACTIVE'}) {
+       unless ($warned || $ENV{'HARNESS_ACTIVE'}) {
             warn "Too late to safely run transaction-batch scrips!"
                 ." This is typically caused by using ticket objects"
                 ." at the top-level of a script which uses the RT API."
                ." Be sure to explicitly undef such ticket objects,"
                 ." or put them inside of a lexical scope.";
+            # Do not suppress repeated warnings if we are in DevelMode
+            unless (RT->Config->Get('DevelMode')) {
+                $warned = 1;
+            }
         }
         return;
     }

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


More information about the rt-commit mailing list