[Rt-commit] rt branch 4.4/improve-unique-value-cf-messages created. rt-4.4.5-32-g8899520ddf

BPS Git Server git at git.bestpractical.com
Mon Mar 28 14:48:34 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, 4.4/improve-unique-value-cf-messages has been created
        at  8899520ddfebd0fbb83739974fce00aceaa07637 (commit)

- Log -----------------------------------------------------------------
commit 8899520ddfebd0fbb83739974fce00aceaa07637
Author: Brian Conry <bconry at bestpractical.com>
Date:   Mon Mar 28 09:35:30 2022 -0500

    Improve error messages with custom field value validation
    
    The prior messages for for a "unique values" custom field didn't include
    either the name of the custom field or the value that violated the
    constraint, making it difficult in some configurations to identify which
    custom field was in error.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index e449c86bbc..0f08d8dbc8 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1827,12 +1827,13 @@ sub AddValueForObject {
     if ($self->UniqueValues) {
         my $class = $self->CollectionClassFromLookupType($self->ObjectTypeFromLookupType);
         my $collection = $class->new(RT->SystemUser);
-        $collection->LimitCustomField(CUSTOMFIELD => $self->Id, OPERATOR => '=', VALUE => $args{'LargeContent'} // $args{'Content'});
+        my $value = $args{'LargeContent'} // $args{'Content'};
+        $collection->LimitCustomField(CUSTOMFIELD => $self->Id, OPERATOR => '=', VALUE => $value);
 
         if ($collection->Count) {
             $RT::Logger->debug( "Non-unique custom field value for CF #" . $self->Id ." with object custom field value " . $collection->First->Id );
             $RT::Handle->Rollback();
-            return ( 0, $self->loc('That is not a unique value') );
+            return ( 0, $self->loc("'[_1]' is not a unique value", $value) );
         }
     }
 
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 8138b87418..d57b6b00cf 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -2019,7 +2019,7 @@ sub _AddCustomFieldValue {
         );
 
         unless ( $new_value_id ) {
-            return ( 0, $self->loc( "Could not add new custom field value: [_1]", $value_msg ) );
+            return ( 0, $self->loc( "Could not add a new value to custom field '[_2]': [_1]", $value_msg, $cf->Name ) );
         }
 
         my $new_value = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
diff --git a/t/customfields/unique_values.t b/t/customfields/unique_values.t
index 577bbbb794..9ef501c43e 100644
--- a/t/customfields/unique_values.t
+++ b/t/customfields/unique_values.t
@@ -31,7 +31,7 @@ use RT::Test tests => undef;
         ( $ret, $msg ) =
           $beta->AddCustomFieldValue( Field => $unique_single, Value => $foo );
         ok( !$ret, "can't reuse the OCFV 'foo'");
-        like($msg, qr/That is not a unique value/);
+        like($msg, qr/ is not a unique value/);
         is( $beta->FirstCustomFieldValue($unique_single), undef, 'no value since it was a duplicate' );
 
         ( $ret, $msg ) =
diff --git a/t/web/cf_groupings.t b/t/web/cf_groupings.t
index a872617c49..4babda6d1e 100644
--- a/t/web/cf_groupings.t
+++ b/t/web/cf_groupings.t
@@ -112,7 +112,7 @@ my $id = $m->get_ticket_id;
             with_fields => { $input_name => "bad value" },
             button      => 'SubmitTicket',
         });
-        $m->content_like(qr{Could not add new custom field value: Input must match});
+        $m->content_like(qr{Could not add a new value to custom field &\#39;Test$name&\#39;: Input must match \Q^(?!bad value).*\E\$});
     }
 }
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list