Problem with CF for Users

Hi all,

we’ve a problem with custom fields for users on rt 3.8.8.

Here is my problem:

Step1
We add a value to a user cf, lets say ‘String1 = ABCDEFGH’

$UserObject->AddCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String1,“RecordTransaction” => 0);

Step2
Then we limit a user object to this cf value to find all users with this
value in our user base.

$Users1->LimitCustomField(“CUSTOMFIELD” => $MStatusId,
“OPERATOR” => “=”,
“VALUE” => $String1 );

That works fine!

Step3 Error
We change the value from ‘ABCDEFGH’ to 'RSTUVWXYZ’
and limit the object to ‘ABCDEFGH’ the user with the new value is shown
in the result.

With Ticket objects this works fine.

Any comments?

Cheers,
Bj�rn

here is a little script that shows the problem:

#!/usr/bin/perl -w
use strict;
use lib “/opt/rt3/RTIM/lib”, “/opt/rt3/lib”;
use RT;
RT::LoadConfig();
RT::Init();
use RT::Interface::CLI “GetCurrentUser”, “loc”;
use RT::Users;

my $CurrentUser = GetCurrentUser();
my $Users1 = new RT::Users($CurrentUser);
my $Users2 = new RT::Users($CurrentUser);
my $UserObject = RT::User->new($CurrentUser);
my ($String1, $String2) = (“ABCDEFGH”, “RSTUVWXYZ”);

The customfield #126 is a user customfield whose name is

‘MergeStatus’

my $MStatusId = 126;
my $MStatusName = “MergeStatus”;

The number has to be an id of an existing user!

$UserObject->Load(14788);

The customfield #126 of the user is being changed to ‘ABCDEFGH’.

$UserObject->AddCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String1,“RecordTransaction” => 0);
$Users1->LimitCustomField(“CUSTOMFIELD” => $MStatusId,
“OPERATOR” => “=”,
“VALUE” => $String1 );

print “Users with the Status $String1\n”;

while (my $UC = $Users1->Next())
{
my $MStatusValue;
my $CFValues = $UC->CustomFieldValues($MStatusId);
while (my $CFValue = $CFValues->Next)
{
$MStatusValue = $CFValue->Content;
}
print join("\t", ($UC->Id, $UC->Name, $UC->RealName, $MStatusValue
)), “\n”;
}
print “\n\n\n”;

The customfield #126 of the user is being changed to ‘RSTUVWXYZ’.

$UserObject->DeleteCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String1,“RecordTransaction” => 0);
$UserObject->AddCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String2,“RecordTransaction” => 0);

$User2 refers to the updated collection

$Users2->LimitCustomField(“CUSTOMFIELD” => $MStatusId,
“OPERATOR” => “=”,
“VALUE” => $String1 );
#User still occurs, although he should not occur anymore!
print “Users with the Status $String1\n”;
while (my $UC = $Users1->Next())
{
my $MStatusValue;
my $CFValues = $UC->CustomFieldValues($MStatusId);
while (my $CFValue = $CFValues->Next)
{
$MStatusValue = $CFValue->Content;
}
print join("\t", ($UC->Id, $UC->Name, $UC->RealName, $MStatusValue
)), “\n”;
}

Hi all,

we’ve a problem with custom fields for users on rt 3.8.8.

It is worth noting that Tickets_Overlay.pm has a LimitCustomField but
Users is falling back to the generic code in RT::SearchBuilder.
I suggest a ->BuildSelectQuery to confirm what the sql is doing, but
if I had to guess, I’d suspect that Users isn’t skipping disabled OCFV
records, which means that the old value for that user is found.

-kevin

Hi Kevin,

Hi all,

we’ve a problem with custom fields for users on rt 3.8.8.

It is worth noting that Tickets_Overlay.pm has a LimitCustomField but
Users is falling back to the generic code in RT::SearchBuilder.
I suggest a ->BuildSelectQuery to confirm what the sql is doing, but
if I had to guess, I’d suspect that Users isn’t skipping disabled OCFV
records, which means that the old value for that user is found.

sql is doing everything right.

mysql> select Customfield, ObjectType, ObjectId, Content, Disabled from
ObjectCustomFieldValues where ObjectType =‘RT::User’ and
Customfield=126 and ObjectId=1227122;
| Customfield | ObjectType | ObjectId | Content | Disabled |
| 126 | RT::User | 1227122 | A9428 | 1 |
| 126 | RT::User | 1227122 | A9488 | 0 |
2 rows in set (0.00 sec)

Do you thing this is a bug?

Cheers,
Bjï¿œrn

Hi Kevin,

Am 08.02.11 17:40, schrieb Kevin Falcone:

Hi all,

we’ve a problem with custom fields for users on rt 3.8.8.

It is worth noting that Tickets_Overlay.pm has a LimitCustomField but
Users is falling back to the generic code in RT::SearchBuilder.
I suggest a ->BuildSelectQuery to confirm what the sql is doing, but
if I had to guess, I’d suspect that Users isn’t skipping disabled OCFV
records, which means that the old value for that user is found.

sql is doing everything right.

That appears to be custom SQL, I meant what does BuildSelectQuery spit
out for the ticket vs the user and extra where clauses.

If I’m correct, adding an explicit Limit for FIELD => Disabled, Value
=> 0 it’ll fix things.

mysql> select Customfield, ObjectType, ObjectId, Content, Disabled from
ObjectCustomFieldValues where ObjectType =‘RT::User’ and
Customfield=126 and ObjectId=1227122;
±------------±-----------±---------±--------±---------+
| Customfield | ObjectType | ObjectId | Content | Disabled |
±------------±-----------±---------±--------±---------+
| 126 | RT::User | 1227122 | A9428 | 1 |
| 126 | RT::User | 1227122 | A9488 | 0 |
±------------±-----------±---------±--------±---------+
2 rows in set (0.00 sec)

Do you thing this is a bug?

I’m not sure what changing Record’s LimieCustomField would do to the
rest of RT without trying it and running the test suite.

-kevin

Hi Kevin,

Hi Kevin,

Am 08.02.11 17:40, schrieb Kevin Falcone:

Hi all,

we’ve a problem with custom fields for users on rt 3.8.8.

It is worth noting that Tickets_Overlay.pm has a LimitCustomField but
Users is falling back to the generic code in RT::SearchBuilder.
I suggest a ->BuildSelectQuery to confirm what the sql is doing, but
if I had to guess, I’d suspect that Users isn’t skipping disabled OCFV
records, which means that the old value for that user is found.

sql is doing everything right.

That appears to be custom SQL, I meant what does BuildSelectQuery spit
out for the ticket vs the user and extra where clauses.

If I’m correct, adding an explicit Limit for FIELD => Disabled, Value
=> 0 it’ll fix things.

mysql> select Customfield, ObjectType, ObjectId, Content, Disabled from
ObjectCustomFieldValues where ObjectType =‘RT::User’ and
Customfield=126 and ObjectId=1227122;
±------------±-----------±---------±--------±---------+
| Customfield | ObjectType | ObjectId | Content | Disabled |
±------------±-----------±---------±--------±---------+
| 126 | RT::User | 1227122 | A9428 | 1 |
| 126 | RT::User | 1227122 | A9488 | 0 |
±------------±-----------±---------±--------±---------+
2 rows in set (0.00 sec)

Do you thing this is a bug?

I’m not sure what changing Record’s LimieCustomField would do to the
rest of RT without trying it and running the test suite.

Wolfram added some line to /opt/rt3/lib/RT/SearchBuilder.pm on our 3.8.7
RT.
diff /opt/rt3/lib/RT/SearchBuilder.pm SearchBuilder.pm
262a263,268

$self->Limit(

“ALIAS” => $alias,
“FIELD” => ‘Disabled’,
“OPERATOR” => “=”,
“VALUE” => 0,
);

It seems that it works, but how can we use the test suite to be sure
that all works fine?

Cheers,
Bjï¿œrn

I’m not sure what changing Record’s LimieCustomField would do to the
rest of RT without trying it and running the test suite.

Wolfram added some line to /opt/rt3/lib/RT/SearchBuilder.pm on our 3.8.7
RT.
diff /opt/rt3/lib/RT/SearchBuilder.pm SearchBuilder.pm
262a263,268

$self->Limit(
"ALIAS"      => $alias,
"FIELD"      => 'Disabled',
"OPERATOR"   => "=",
"VALUE"      => 0,
);

It seems that it works, but how can we use the test suite to be sure
that all works fine?

You mean, how do you run the test suite?

RT’s test suite assumes that it has a database server where it can
connect and create an rt3test database (or multiple databases if
you’re running the test suite in parallel, but we’ll ignore that).

So, you probably want a clean rt-3.8.9 directory with your patch
applied where you run:

./configure --enable-layout=inplace --with-db-host=yourtesthost
or possibly
./configure --enable-layout=inplace --with-db-type=SQLite
although I prefer testing on mysql or pg to sqlite, but it requires
more infrastructure tweaking.

then you run

RT_DBA_USER=userwhocancreatedb RT_DBA_PASSWORD=password make test

Isolating this from your production servers is highly recommended,
although you should have to work really hard to get it to clobber your
actual rt3 database.

-kevin

Hi all,

we’ve a problem with custom fields for users on rt 3.8.8.

Here is my problem:

Step1
We add a value to a user cf, lets say ‘String1 = ABCDEFGH’

$UserObject->AddCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String1,“RecordTransaction” => 0);

Step2
Then we limit a user object to this cf value to find all users with this
value in our user base.

$Users1->LimitCustomField(“CUSTOMFIELD” => $MStatusId,
“OPERATOR” => “=”,
“VALUE” => $String1 );

That works fine!

Step3 Error
We change the value from ‘ABCDEFGH’ to 'RSTUVWXYZ’
and limit the object to ‘ABCDEFGH’ the user with the new value is shown
in the result.

With Ticket objects this works fine.

Any comments?

Cheers,
Bjï¿œrn

here is a little script that shows the problem:

#!/usr/bin/perl -w
use strict;
use lib “/opt/rt3/RTIM/lib”, “/opt/rt3/lib”;
use RT;
RT::LoadConfig();
RT::Init();
use RT::Interface::CLI “GetCurrentUser”, “loc”;
use RT::Users;

my $CurrentUser = GetCurrentUser();
my $Users1 = new RT::Users($CurrentUser);
my $Users2 = new RT::Users($CurrentUser);
my $UserObject = RT::User->new($CurrentUser);
my ($String1, $String2) = (“ABCDEFGH”, “RSTUVWXYZ”);

The customfield #126 is a user customfield whose name is

‘MergeStatus’

my $MStatusId = 126;
my $MStatusName = “MergeStatus”;

The number has to be an id of an existing user!

$UserObject->Load(14788);

The customfield #126 of the user is being changed to ‘ABCDEFGH’.

$UserObject->AddCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String1,“RecordTransaction” => 0);
$Users1->LimitCustomField(“CUSTOMFIELD” => $MStatusId,
“OPERATOR” => “=”,
“VALUE” => $String1 );

print “Users with the Status $String1\n”;

while (my $UC = $Users1->Next())
{
my $MStatusValue;
my $CFValues = $UC->CustomFieldValues($MStatusId);
while (my $CFValue = $CFValues->Next)
{
$MStatusValue = $CFValue->Content;
}
print join("\t", ($UC->Id, $UC->Name, $UC->RealName, $MStatusValue
)), “\n”;
}
print “\n\n\n”;

The customfield #126 of the user is being changed to ‘RSTUVWXYZ’.

$UserObject->DeleteCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String1,“RecordTransaction” => 0);
$UserObject->AddCustomFieldValue(“Field” => $MStatusName, “Value” =>
$String2,“RecordTransaction” => 0);

$User2 refers to the updated collection

$Users2->LimitCustomField(“CUSTOMFIELD” => $MStatusId,
“OPERATOR” => “=”,
“VALUE” => $String1 );
#User still occurs, although he should not occur anymore!
print “Users with the Status $String1\n”;
while (my $UC = $Users1->Next())
{
my $MStatusValue;
my $CFValues = $UC->CustomFieldValues($MStatusId);
while (my $CFValue = $CFValues->Next)
{
$MStatusValue = $CFValue->Content;
}
print join("\t", ($UC->Id, $UC->Name, $UC->RealName, $MStatusValue
)), “\n”;
}