Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bestpractical/rt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsunnavy <sunnavy@bestpractical.com>2022-03-18 22:28:42 +0300
committersunnavy <sunnavy@bestpractical.com>2022-03-21 21:31:49 +0300
commit531cb3b363ddb858edc827fcbc085140f0e0c4c2 (patch)
tree1aab04d848e2397485ba3f0c80e043e69d9ec012
parent1d7aba58e8dd98c56527940999d5ed609ac8f03d (diff)
Search attributes with extra limits on a clean cloned search builder object5.0/fix-initialdata-attributes-search
"Attributes" method returns a cached search builder object, so if we want to add extra limits, we shouldn't touch the original cached object, otherwise the query wouldn't be right, e.g. my $attributes = $object->Attributes; $attributes->Limit( FIELD => 'Name', VALUE => 'Dashboard' ); $attributes->Limit( FIELD => 'Description', VALUE => 'foo' ); Later, my $attributes = $object->Attributes; $attributes->Limit( FIELD => 'Name', VALUE => 'Dashboard' ); $attributes->Limit( FIELD => 'Description', VALUE => 'bar' ); For $RT::System, as we don't re-initialize it much, the 2 snippets above share the same $object, this would unexpectedly get global dashboards with Description "foo" *or* "bar". Note that it's not enough to create a brand new object every time in _LoadObject, as _UpdateObject uses the same object in a loop, where attribute searches occur.
-rw-r--r--lib/RT/Handle.pm12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 3f741fa7ff..2bc5b3ce7d 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2409,7 +2409,7 @@ sub _UpdateObject {
if ( my $items = delete $values->{$type} ) {
if ( $type eq 'Attributes' ) {
for my $item ( @$items ) {
- my $attributes = $object->Attributes;
+ my $attributes = $object->Attributes->Clone;
$attributes->Limit( FIELD => 'Name', VALUE => $item->{Name} );
$attributes->Limit( FIELD => 'Description', VALUE => $item->{Description} );
if ( my $attribute = $attributes->First ) {
@@ -2783,7 +2783,7 @@ sub _LoadObject {
$RT::Logger->error( "Invalid object $obj" );
return;
}
- my $attributes = $obj->Attributes;
+ my $attributes = $obj->Attributes->Clone;
$attributes->Limit( FIELD => 'Name', VALUE => $values->{_Original}{Name} );
$attributes->Limit( FIELD => 'Description', VALUE => $values->{_Original}{Description} );
if ( my $attribute = $attributes->First ) {
@@ -2809,7 +2809,7 @@ sub _CanonilizeAttributeContent {
next unless $entry->{portlet_type} eq 'search';
if ( $entry->{ObjectType} && $entry->{ObjectId} && $entry->{Description} ) {
if ( my $object = $self->_LoadObject( $entry->{ObjectType}, $entry->{ObjectId} ) ) {
- my $attributes = $object->Attributes;
+ my $attributes = $object->Attributes->Clone;
$attributes->Limit( FIELD => 'Description', VALUE => $entry->{Description} );
if ( my $attribute = $attributes->First ) {
$entry->{id} = $attribute->id;
@@ -2827,7 +2827,7 @@ sub _CanonilizeAttributeContent {
for my $entry ( @{ $item->{Content}{dashboards} } ) {
if ( $entry->{ObjectType} && $entry->{ObjectId} && $entry->{Description} ) {
if ( my $object = $self->_LoadObject( $entry->{ObjectType}, $entry->{ObjectId} ) ) {
- my $attributes = $object->Attributes;
+ my $attributes = $object->Attributes->Clone;
$attributes->Limit( FIELD => 'Name', VALUE => 'Dashboard' );
$attributes->Limit( FIELD => 'Description', VALUE => $entry->{Description} );
if ( my $attribute = $attributes->First ) {
@@ -2842,7 +2842,7 @@ sub _CanonilizeAttributeContent {
my $entry = $item->{Content};
if ( $entry->{ObjectType} && $entry->{ObjectId} && $entry->{Description} ) {
if ( my $object = $self->_LoadObject( $entry->{ObjectType}, $entry->{ObjectId} ) ) {
- my $attributes = $object->Attributes;
+ my $attributes = $object->Attributes->Clone;
$attributes->Limit( FIELD => 'Name', VALUE => 'Dashboard' );
$attributes->Limit( FIELD => 'Description', VALUE => $entry->{Description} );
if ( my $attribute = $attributes->First ) {
@@ -2855,7 +2855,7 @@ sub _CanonilizeAttributeContent {
my $entry = $item->{Content}{DashboardId};
if ( $entry->{ObjectType} && $entry->{ObjectId} && $entry->{Description} ) {
if ( my $object = $self->_LoadObject( $entry->{ObjectType}, $entry->{ObjectId} ) ) {
- my $attributes = $object->Attributes;
+ my $attributes = $object->Attributes->Clone;
$attributes->Limit( FIELD => 'Name', VALUE => 'Dashboard' );
$attributes->Limit( FIELD => 'Description', VALUE => $entry->{Description} );
if ( my $attribute = $attributes->First ) {