[Rt-commit] rt branch, 4.4/only-warn-once-about-unsafe-scrips-in-global-destruction, created. rt-4.4.4-142-ge8c211180e
Dianne Skoll
dianne at bestpractical.com
Tue Sep 22 16:30:56 EDT 2020
The branch, 4.4/only-warn-once-about-unsafe-scrips-in-global-destruction has been created
at e8c211180e70b177d9dfb9eff03bf3382bc59291 (commit)
- Log -----------------------------------------------------------------
commit e8c211180e70b177d9dfb9eff03bf3382bc59291
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.
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 81224831cc..1e3de38467 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,13 @@ 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.";
+ $warned = 1;
}
return;
}
-----------------------------------------------------------------------
More information about the rt-commit
mailing list