[Rt-devel] RT 3.6.5 RT::SearchBuilder bug report and patch

Stephen Turner sturner at MIT.EDU
Tue Nov 6 13:55:29 EST 2007


Hello,

In tracking down an apparent difference between RT 3.4 and 3.6, I've 
found what appears to be a bug, or at least an inconsistency in 3.6. 
It's causing several of my perl scripts that use the RT API to fail.

The difference between 3.4 & 3.6 is that in 3.6, objects have to have 
CurrentUser actually be a RT::CurrentUser object. 3.4 allowed 
CurrentUser to be a RT::User or RT:CurrentUser.

The inconsistency (in 3.6) is that collection objects behave 
differently from single-row objects:

With an RT::User object called $UserObj, if you do:

   my $tkt = RT::Ticket->new ($UserObj);

then $tkt->CurrentUser will automatically be set to an 
RT::CurrentUser object for you, and life is good.

However, if you do:

   my $tkts = RT::Tickets->new ($UserObj);

you'll get this error:

[err]: RT::Tickets=HASH(0xaeaf1b4) was created without a CurrentUser. 
Any RT object which is subclass of RT::Base must be created with a 
RT::CurrentUser or a RT::User obejct as the first argument. 
(/var/local/rt364/lib/RT/Base.pm:107)
[crit]: RT::Tickets=HASH(0xaeaf1b4) was created without a CurrentUser 
at /var/local/rt364/lib/RT/SearchBuilder.pm line 85

As an aside, the first error message implies that using an RT::User 
object is OK whereas it isn't.

I'd like to suggest a patch to RT/SearchBuilder.pm that will do the 
right thing if you supply an RT::User object to "new" on a 
collection. The patch is based on RT 3.6.5. (This patch also has the 
effect of making the error message correct. Well, except for "obejct"! ).

Steve


--- SearchBuilder.pm.base       2007-11-06 13:40:03.000000000 -0500
+++ SearchBuilder.pm    2007-11-06 13:39:20.000000000 -0500
@@ -80,7 +80,7 @@
      my $self = shift;

      $self->{'user'} = shift;
-    unless(defined($self->CurrentUser)) {
+    unless(defined($self->CurrentUser( $self->{'user'} ))) {
         use Carp;
         Carp::confess("$self was created without a CurrentUser");
         $RT::Logger->err("$self was created without a CurrentUser");




Stephen Turner
Senior Programmer/Analyst - Client Support Services
MIT Information Services and Technology (IS&T)




More information about the Rt-devel mailing list