RT 3.6.5 RT::SearchBuilder bug report and patch

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)

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.

It’s actually something we tightened up. In RT 3.4, the loose behaviour
caused a lot of subtle bugs further down the chain.

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

That’s not good.

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”! ).

That seems reasonable, but will break RT 3.7 as RT::CurrentUser now ISA
RT::User. Ruz, thoughts?