[Rt-commit] rt branch 5.0/fix-initialdata-attributes-search created. rt-5.0.2-113-g531cb3b363
BPS Git Server
git at git.bestpractical.com
Mon Mar 21 18:45:41 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/fix-initialdata-attributes-search has been created
at 531cb3b363ddb858edc827fcbc085140f0e0c4c2 (commit)
- Log -----------------------------------------------------------------
commit 531cb3b363ddb858edc827fcbc085140f0e0c4c2
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Mar 19 03:28:42 2022 +0800
Search attributes with extra limits on a clean cloned search builder object
"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.
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 ) {
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list