DBIx::SearchBuilder and RT2

Our RT2 installation runs into an endless loop in the following
DBIx::SearchBuilder code in SearchBuild/Handler/Pg.pm (version 0.97):

this code is all hacky and evil. but people desperately want something and I’m

super tired. refactoring gratefully appreciated.

sub _BuildJoins {
my $self = shift;
my $sb = shift;
my %seen_aliases;

$seen_aliases{'main'} = 1;

my $join_clause =$sb->{'table'} . " main " ;

my @keys = ( keys %{ $sb->{'left_joins'} } );

while ( my $join = shift @keys ) {
    if ( $seen_aliases{ $sb->{'left_joins'}{$join}{'depends_on'} } ) {
        $join_clause  = "(" . $join_clause;
        $join_clause .= $sb->{'left_joins'}{$join}{'alias_string'} . " ON (";
        $join_clause .=
          join ( ') AND( ', values %{ $sb->{'left_joins'}{$join}{'criteria'} }
          );
        $join_clause .= ")) ";

        $seen_aliases{$join} = 1;
    }
    else {
        push ( @keys, $join );
    }

}
return (
                join ( ", ", ($join_clause, @{ $sb->{'aliases'} }))) ;

}

@keys has got a single element, and the else branch of the if is
taken. Which means, of course, that the single element in @keys is
constantly removed and added again.

What is the code supposed to do?

Current mail filters: many dial-up/DSL/cable modem hosts, and the
following domains: bigpond.com, di-ve.com, hotmail.com, jumpy.it,
libero.it, netscape.net, postino.it, simplesnet.pt, spymac.com,
tatanova.com, tiscali.co.uk, tiscali.cz, tiscali.it, voila.fr, yahoo.com.

@keys has got a single element, and the else branch of the if is
taken. Which means, of course, that the single element in @keys is
constantly removed and added again.

What is the code supposed to do?

The code is supposed to make sure you don’t join on a table that
hasn’t been listed yet. It’s probably sufficient to put a check to make
sure there’s not a single element there. Can you build up a simple
failure case?

  • Jesse Vincent:

@keys has got a single element, and the else branch of the if is
taken. Which means, of course, that the single element in @keys is
constantly removed and added again.

What is the code supposed to do?

The code is supposed to make sure you don’t join on a table that
hasn’t been listed yet. It’s probably sufficient to put a check to make
sure there’s not a single element there. Can you build up a simple
failure case?

Elements/MyRequests in RT 2.0.15 triggers it, during a call to
RT::ticket::Next. The query is constructed as follws:

my $MyTickets;
$MyTickets = new RT::Tickets ($session{‘CurrentUser’});
$MyTickets->LimitRequestor(VALUE => $session{‘CurrentUser’}->EmailAddress);
$MyTickets->LimitStatus(VALUE => “open”);
$MyTickets->LimitStatus(VALUE => “new”);
$MyTickets->OrderBy(FIELD => ‘Priority’, ORDER => ‘DESC’);
$MyTickets->RowsPerPage(25);

Current mail filters: many dial-up/DSL/cable modem hosts, and the
following domains: bigpond.com, di-ve.com, hotmail.com, jumpy.it,
libero.it, netscape.net, postino.it, simplesnet.pt, spymac.com,
tatanova.com, tiscali.co.uk, tiscali.cz, tiscali.it, voila.fr, yahoo.com.

Elements/MyRequests in RT 2.0.15 triggers it, during a call to
RT::ticket::Next. The query is constructed as follws:

my $MyTickets;
$MyTickets = new RT::Tickets ($session{‘CurrentUser’});
$MyTickets->LimitRequestor(VALUE => $session{‘CurrentUser’}->EmailAddress);
$MyTickets->LimitStatus(VALUE => “open”);
$MyTickets->LimitStatus(VALUE => “new”);
$MyTickets->OrderBy(FIELD => ‘Priority’, ORDER => ‘DESC’);
$MyTickets->RowsPerPage(25);

Can you send us a Data::Dumper dump of the $MyTickets right after the
RowsPerPage ?

  • Jesse Vincent:> On Wed, May 26, 2004 at 06:32:02AM +0200, Florian Weimer wrote:

Elements/MyRequests in RT 2.0.15 triggers it, during a call to
RT::ticket::Next. The query is constructed as follws:

my $MyTickets;
$MyTickets = new RT::Tickets ($session{‘CurrentUser’});
$MyTickets->LimitRequestor(VALUE => $session{‘CurrentUser’}->EmailAddress);
$MyTickets->LimitStatus(VALUE => “open”);
$MyTickets->LimitStatus(VALUE => “new”);
$MyTickets->OrderBy(FIELD => ‘Priority’, ORDER => ‘DESC’);
$MyTickets->RowsPerPage(25);

Can you send us a Data::Dumper dump of the $MyTickets right after the
RowsPerPage ?

You mean, like this? I’ve replaced some output with “sanitized
(e.g. passwords).

$VAR1 = bless( {
‘alias_count’ => 0,
‘where_clause’ => ‘’,
‘table’ => ‘Tickets’,
‘order_clause’ => ‘ORDER BY main.Priority DESC’,
‘RecalcTicketLimits’ => 1,
‘tables’ => ‘’,
‘is_limited’ => 0,
‘order’ => ‘’,
‘restriction_index’ => 4,
‘user’ => bless( {
‘_PrimaryKeys’ => [
‘id’
],
‘_AccessibleCache’ => {
‘Password’ => {
‘neither’ => 1
},
‘IsAdministrator’ => {
‘read’ => 1
},
‘Privileged’ => {
‘read’ => 1
},
‘RealName’ => {
‘read’ => 1
},
‘Name’ => {
‘read’ => 1
},
‘EmailAddress’ => {
‘read’ => 1
},
‘Gecos’ => {
‘read’ => 1
}
},
‘_CacheConfig’ => {
‘cache_key’ => ‘Users:id=4’,
‘cache_for_sec’ => 5,
‘cache_p’ => 1
},
‘user’ => $VAR1->{‘user’},
‘table’ => ‘Users’,
‘UserObj’ => bless( {
‘rights’ => {
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:15:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:9:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:12:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:8:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:17:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:23:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:System:IsRequestor::Right:ModifySelf:IsAdminCc::IsCc::AppliesTo:0:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:4:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:7:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:1:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:13:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:21:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:ShowTicket:IsAdminCc::IsCc::AppliesTo:20:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:2:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:3:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:18:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:11:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:5:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:10:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:17:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:19:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:6:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:14:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:18:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:23:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:6:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:12:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:20:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:20:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:14:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:13:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:4:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:15:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:ShowTicket:IsAdminCc::IsCc::AppliesTo:21:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:3:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:19:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:16:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:8:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:16:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:9:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:21:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:22:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:ShowTicket:IsAdminCc::IsCc::AppliesTo:1:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:5:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:10:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:2:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:22:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:11:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:CreateTicket:IsAdminCc::IsCc::AppliesTo:1:ExtendedPrincipals::IsOwner:’ => 1,
‘4:Scope:Queue:IsRequestor::Right:SeeQueue:IsAdminCc::IsCc::AppliesTo:7:ExtendedPrincipals::IsOwner:’ => 1
},
‘_AccessibleCache’ => {
‘WebEncoding’ => {
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘Privileged’ => {
‘admin’ => 1,
‘read’ => 1,
‘write’ => 1
},
‘AuthSystem’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘Password’ => {
‘write’ => 1
},
‘MobilePhone’ => {
‘read’ => 1,
‘write’ => 1
},
‘Disabled’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘WorkPhone’ => {
‘read’ => 1,
‘write’ => 1
},
‘LastUpdated’ => {
‘auto’ => 1,
‘read’ => 1
},
‘PagerPhone’ => {
‘read’ => 1,
‘write’ => 1
},
‘ExternalContactInfoId’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘ContactInfoSystem’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘Creator’ => {
‘auto’ => 1,
‘read’ => 1
},
‘LastUpdatedBy’ => {
‘auto’ => 1,
‘read’ => 1
},
‘HomePhone’ => {
‘read’ => 1,
‘write’ => 1
},
‘Address1’ => {
‘read’ => 1,
‘write’ => 1
},
‘Created’ => {
‘auto’ => 1,
‘read’ => 1
},
‘ExternalAuthId’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘Comments’ => {
‘admin’ => 1,
‘read’ => 1,
‘write’ => 1
},
‘NickName’ => {
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘Address2’ => {
‘read’ => 1,
‘write’ => 1
},
‘FreeformContactInfo’ => {
‘read’ => 1,
‘write’ => 1
},
‘RealName’ => {
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘City’ => {
‘read’ => 1,
‘write’ => 1
},
‘EmailAddress’ => {
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘EmailEncoding’ => {
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘State’ => {
‘read’ => 1,
‘write’ => 1
},
‘Signature’ => {
‘read’ => 1,
‘write’ => 1
},
‘Zip’ => {
‘read’ => 1,
‘write’ => 1
},
‘Organization’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘PagerEmailAddress’ => {
‘read’ => 1,
‘write’ => 1
},
‘Lang’ => {
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘Gecos’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
},
‘Country’ => {
‘read’ => 1,
‘write’ => 1
},
‘Name’ => {
‘admin’ => 1,
‘read’ => 1,
‘public’ => 1,
‘write’ => 1
}
},
‘_CacheConfig’ => {
‘cache_for_sec’ => 5,
‘cache_p’ => 1
},
‘table’ => ‘Users’,
‘values’ => {
‘creator’ => ‘3’,
‘comments’ => undef,
‘state’ => undef,
‘webencoding’ => undef,
‘realname’ => ‘Florian Weimer’,
‘password’ => 'sanitized,
‘authsystem’ => ‘X.500’,
‘homephone’ => undef,
‘id’ => ‘4’,
‘lang’ => undef,
‘name’ => ‘Florian Weimer’,
‘privileged’ => ‘1’,
‘contactinfosystem’ => undef,
‘zip’ => undef,
‘emailencoding’ => undef,
‘lastupdated’ => ‘2004-01-09 20:56:47+00’,
‘signature’ => ‘sanitized’,
‘externalauthid’ => ‘/C=DE/O=Universitaet Stuttgart/OU=Rechenzentrum/OU=RUS-CERT/CN=Florian Weimer/Email=Weimer@CERT.Uni-Stuttgart.DE’,
‘address1’ => undef,
‘workphone’ => ‘sanitized’,
‘emailaddress’ => ‘Weimer@CERT.Uni-Stuttgart.DE’,
‘freeformcontactinfo’ => undef,
‘disabled’ => ‘0’,
‘city’ => undef,
‘gecos’ => ‘rusfw’,
‘organization’ => ‘Universitaet Stuttgart’,
‘country’ => undef,
‘mobilephone’ => undef,
‘nickname’ => ‘fw’,
‘externalcontactinfoid’ => undef,
‘address2’ => undef,
‘created’ => ‘2002-03-08 22:51:54+00’,
‘pagerphone’ => undef,
‘lastupdatedby’ => ‘4’
},
‘_PrimaryKeys’ => [
‘id’
],
‘user’ => $VAR1->{‘user’},
‘fetched’ => {
‘creator’ => 1,
‘comments’ => 1,
‘state’ => 1,
‘webencoding’ => 1,
‘realname’ => 1,
‘password’ => 1,
‘authsystem’ => 1,
‘homephone’ => 1,
‘id’ => 1,
‘lang’ => 1,
‘name’ => 1,
‘privileged’ => 1,
‘contactinfosystem’ => 1,
‘zip’ => 1,
‘emailencoding’ => 1,
‘signature’ => 1,
‘lastupdated’ => 1,
‘externalauthid’ => 1,
‘address1’ => 1,
‘workphone’ => 1,
‘emailaddress’ => 1,
‘freeformcontactinfo’ => 1,
‘disabled’ => 1,
‘city’ => 1,
‘gecos’ => 1,
‘organization’ => 1,
‘country’ => 1,
‘mobilephone’ => 1,
‘nickname’ => 1,
‘externalcontactinfoid’ => 1,
‘address2’ => 1,
‘created’ => 1,
‘lastupdatedby’ => 1,
‘pagerphone’ => 1
}
}, ‘RT::User’ ),
‘values’ => $VAR1->{‘user’}{‘UserObj’}{‘values’},
‘fetched’ => $VAR1->{‘user’}{‘UserObj’}{‘fetched’}
}, ‘RT::CurrentUser’ ),
‘limit_clause’ => ‘’,
‘DBIxHandle’ => bless( {
‘dsn’ => ‘dbi:Pg:dbname=rt2;host=localhost’,
‘DisconnectHandleOnDestroy’ => undef
}, ‘RT::Handle’ ),
‘primary_key’ => ‘id’,
‘auxillary_tables’ => ‘’,
‘looking_at_effective_id’ => 0,
‘must_redo_search’ => 1,
‘itemscount’ => 0,
‘show_rows’ => 25,
‘table_links’ => ‘’,
‘aliases’ => ,
‘TicketRestrictions’ => {
‘1’ => {
‘FIELD’ => ‘Watcher’,
‘VALUE’ => ‘Weimer@CERT.Uni-Stuttgart.DE’,
‘OPERATOR’ => ‘=’,
‘DESCRIPTION’ => ‘Requestor = Weimer@CERT.Uni-Stuttgart.DE’,
‘TYPE’ => ‘Requestor’
},
‘3’ => {
‘FIELD’ => ‘Status’,
‘VALUE’ => ‘new’,
‘OPERATOR’ => ‘=’,
‘DESCRIPTION’ => ‘Status = new’
},
‘2’ => {
‘FIELD’ => ‘Status’,
‘VALUE’ => ‘open’,
‘OPERATOR’ => ‘=’,
‘DESCRIPTION’ => ‘Status = open’
}
},
‘first_row’ => 0
}, ‘RT::Tickets’ );

Current mail filters: many dial-up/DSL/cable modem hosts, and the
following domains: bigpond.com, di-ve.com, hotmail.com, jumpy.it,
libero.it, netscape.net, postino.it, simplesnet.pt, spymac.com,
tatanova.com, tiscali.co.uk, tiscali.cz, tiscali.it, voila.fr, yahoo.com.