View Issue Details

IDProjectCategoryView StatusLast Update
0014516mantisbtupgradepublic2014-09-23 18:05
ReporterPantsManUK Assigned Todregad  
PrioritylowSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.11 
Target Version1.2.12Fixed in Version1.2.12 
Summary0014516: Custom field needs value when reporting following upgrade to 1.2.11
Description

Not sure how reproducable this will be for others, but following an upgrade from 1.2.8 to 1.2.11 (with some additional local changes to the code for our workflow), one of our custom fields decided that it needed a value at report time (despite "Display When Reporting Issues" being unticked).

We've worked around the problem this caused by giving it a suitable default value and ticking all previously unticked the "Display When..." fields, so this is just a heads-up (and has anyone else seen similar behaviour?).

Additional Information

Screenshots are (1) error on issue submission, and (2) settings for the field in question, prior to adding it to the Report Issue page.

TagsNo tags attached.
Attached Files
Mantis01.png (12,280 bytes)   
Mantis01.png (12,280 bytes)   
Mantis02.png (45,321 bytes)   
Mantis02.png (45,321 bytes)   
0001-Custom-field-validation-should-pass-when-empty-and-m.patch (2,345 bytes)   
From 467d9b60095d50db192819bb20bc52833aaa7227 Mon Sep 17 00:00:00 2001
From: Damien Regad <damien.regad@merckgroup.com>
Date: Mon, 30 Jul 2012 00:03:55 +0200
Subject: [PATCH] Custom field validation should pass when empty and min
 length > 0

Fix for #12029 (commit 9c71d4f884200f682636e772cf3584202fc2443d)
introduced a regression in the validation of numeric custom fields when
the field's minimum length is greater than 0 and the data being
validated is empty. This prevents e.g. reporting of new issues with a
hidden custom field, or updating issues having a non-required, empty
field.

This commit resolves the problem by passing validation when the field is
empty. This should not cause problems for required fields, as that case
is covered by an earlier check in bug_report.php and bug_update.php.

Fixes #14516
---
 core/custom_field_api.php |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/core/custom_field_api.php b/core/custom_field_api.php
index a6faa8a..fd89533 100644
--- a/core/custom_field_api.php
+++ b/core/custom_field_api.php
@@ -1157,21 +1157,29 @@ function custom_field_validate( $p_field_id, $p_value ) {
 			$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
 			break;
 		case CUSTOM_FIELD_TYPE_NUMERIC:
-			$t_valid &= ( $t_length == 0 ) || is_numeric( $p_value );
-			
+			# Empty fields are valid even if minimum length > 0
+			if( $t_length == 0 ) {
+				break;
+			}
+			$t_valid &= is_numeric( $p_value );
+
 			# Check the length of the number
 			$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
 			$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
-			
+
 			break;
 		case CUSTOM_FIELD_TYPE_FLOAT:
+			# Empty fields are valid even if minimum length > 0
+			if( $t_length == 0 ) {
+				break;
+			}
 			# Allow both integer and float numbers
-			$t_valid &= ( $t_length == 0 ) || is_numeric( $p_value ) || is_float( $p_value );
-			
+			$t_valid &= is_numeric( $p_value ) || is_float( $p_value );
+
 			# Check the length of the number
 			$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
 			$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
-			
+
 			break;
 		case CUSTOM_FIELD_TYPE_DATE:
 			# gpc_get_cf for date returns the value from strftime
-- 
1.7.9.5

Relationships

related to 0012029 closedrombert minimum length of custom fields of type numeric is not checked 
related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 
related to 0014533 closedrombert Port '14516: Custom field needs value when reporting following upgrade to 1.2.11' to the SOAP API 

Activities

PantsManUK

PantsManUK

2012-07-26 11:36

reporter   ~0032377

Further update, we are getting the same "Invalid value" error on issue edits where that field currently has no value. I'm going to SQL a fix for that (replace "" with "0000"), but this elevates it in my book to an honest problem, and not just a nuisance.

dregad

dregad

2012-07-26 16:15

developer   ~0032378

What RDBMS are you using ?

PantsManUK

PantsManUK

2012-07-27 03:56

reporter   ~0032382

Last edited: 2012-07-27 07:06

All pertinent data (and apologies for not including it originally Damien):-

Host OS: Ubuntu 10.04 LTS
Apache: 2.2.14
MySQL: 5.1.63 (Percona MySQL build 14.14)

dregad

dregad

2012-07-29 18:01

developer   ~0032397

I can reproduce this behavior on my dev box using the custom field definition you provided in the attached screenshot.

The commit which introduced the problem is 9c71d4f8, released in 1.2.9: fix for 0012029, modifying the custom field validation function

I believe the root cause is that the validation should not fail when the field is empty.

dregad

dregad

2012-07-29 18:24

developer   ~0032398

Please test the attached patch and let me know how it goes

dregad

dregad

2012-07-29 18:35

developer   ~0032399

Reminder sent to: rombert

Can you kindly have a look at this [1] as well ?

I am specifically interested in your feedback because of the call to custom_field_validate() in api/soap/mc_issue_api.php, mci_issue_set_custom_fields() function, which does not seem to contain any logic related to checking for required custom fields (unless this is done elsewhere in the soap api).

[1] https://github.com/dregad/mantisbt/tree/fix-14516

PantsManUK

PantsManUK

2012-07-30 05:45

reporter   ~0032401

Applied your patch, changed the custom field definition back to no default value and don't display when reporting, then added a new case to the project the field applies to. Issue submitted without validation error.

Also, edited an existing issue removing the previous "0000" dummy value from the custom field. Again, issue submitted without validation error.

Many thanks for (a) finding and (b) fixing this one Damien; I consider this issue resolved.

rombert

rombert

2012-07-30 15:54

reporter   ~0032407

(In reply to comment 0014516:0032399)

Can you kindly have a look at this [1] as well ?

I am specifically interested in your feedback because of the call to
custom_field_validate() in api/soap/mc_issue_api.php,
mci_issue_set_custom_fields() function, which does not seem to contain any logic
related to checking for required custom fields (unless this is done elsewhere in
the soap api).

[1] https://github.com/dregad/mantisbt/tree/fix-14516

Thanks for the heads-up, Damien.

Doesn't the call to custom_field_validate on line 173 cover the validation requirements.

dregad

dregad

2012-07-30 16:30

developer   ~0032408

Doesn't the call to custom_field_validate on line 173 cover the validation requirements.

Only partially, in that the function does not check the 'required' status of a custom field, only that its contents are valid.

If you look at the code, the error checking for required field is tested separately, e.g. in bug_report.php line 119


foreach( $t_related_custom_field_ids as $t_id ) {
$t_def = custom_field_get_definition( $t_id );

    # Produce an error if the field is required but wasn't posted
    if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
        ( $t_def['require_report'] ) ) {
        error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
        trigger_error( ERROR_EMPTY_FIELD, ERROR );
    }

    if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) {
        error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
        trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
    }
}


I guess it's done this way in order to return a differentiated error message to the user.

dregad

dregad

2012-07-30 19:39

developer   ~0032410

Based on PantsManUK's feedback in 0014516:0032401 I will push my fix to core.

@rombert if you think, as I do, that SOAP should be amended to check for required custom field, I let you create a separate issue to track it.

atrol

atrol

2012-07-31 05:05

developer   ~0032413

Reminder sent to: dregad

This introduces another issue.
Now I am able to edit an issue and to clear a custom text field also when Min. Length is set > 0

dregad

dregad

2012-07-31 05:14

developer   ~0032414

Thanks for testing, I'll have a look

PantsManUK

PantsManUK

2012-07-31 08:07

reporter   ~0032420

Last edited: 2012-07-31 12:18

@atrol That would seem (to me, at least) to be desired behaviour; right up to the point that it becomes a requirement for the field to have a value, it can be blank.

A direct example, using our own data (since it's displayed above): the "Tested in revision" field clearly has a minimum and maximum length requirement, but it can be blank until it's required (when the issue is marked Resolved or Closed in our case), at which point the minimum/maximum requirements need to be enforced.

@dregad Unfortunately, in my (admittedly limited) testing, despite "Tested in revision" being "Display" and "Required" for Resolve, it neither displayed nor warned that it was empty when I resolved a test issue. It did appear when I Closed the case (and failed validation when left blank).

atrol

atrol

2012-07-31 15:57

developer   ~0032424

The custom field configuration would need some redesign to handle all use cases in a consistent way. Probably nothing to implement in 1.2.x.

@PantsManUK, you are right, I am able to enforce the desired behaviour by checking "Required On Update".

rombert

rombert

2012-07-31 16:13

reporter   ~0032425

(In reply to comment 0014516:0032408)

Doesn't the call to custom_field_validate on line 173 cover the validation
requirements.

Only partially, in that the function does not check the 'required' status of a
custom field, only that its contents are valid.

If you look at the code, the error checking for required field is tested
separately, e.g. in bug_report.php line 119


foreach( $t_related_custom_field_ids as $t_id ) {
$t_def = custom_field_get_definition( $t_id );

Produce an error if the field is required but wasn't posted

if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
( $t_def['require_report'] ) ) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' )
) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

if ( !custom_field_validate( $t_id, gpc_get_custom_field(
"customfield$t_id", $t_def['type'], NULL ) ) ) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' )
) );
trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
}
}


I guess it's done this way in order to return a differentiated error message to
the user.

I've added bug 0014533 to track this for the SOAP API.

dregad

dregad

2012-08-01 07:15

developer   ~0032431

@PantsManUK re 0014516:0032420:

despite "Tested in revision" being "Display" and "Required" for Resolve, it
neither displayed nor warned that it was empty when I resolved a test issue. It
did appear when I Closed the case (and failed validation when left blank).

I am not able to reproduce this here (i.e. custom field is both displayed and required when resolving issue), and I wonder whether your problem is caused by your using a non-standard mantis, as you mention in the bug's description

with some additional local changes to the code for our workflow.

Please try again with a standard MantisBT codebase and let me know if problem persists, if possible with detailed steps to reproduce.

dregad

dregad

2012-08-13 09:21

developer   ~0032551

@PantsManUK - as you have not provided any feedback on my earlier note, I am resolving this again.

Feel free to reopen if you can provide steps to reproduce the issue.

grangeway

grangeway

2013-04-05 17:56

reporter   ~0036169

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master c2d701e8

2012-07-29 11:03

dregad


Details Diff
Custom field validation should pass when empty and min length > 0

Fix for 0012029 (commit dd286bf898f3e9ee330f7c4512cf5ca9437d521e)
introduced a regression in the validation of numeric custom fields when
the field's minimum length is greater than 0 and the data being
validated is empty. This prevents e.g. reporting of new issues with a
hidden custom field, or updating issues having a non-required, empty
field.

This commit resolves the problem by passing validation when the field is
empty. This should not cause problems for required fields, as that case
is covered by an earlier check in bug_report.php and bug_update.php.

Fixes 0014516
Affected Issues
0014516
mod - core/custom_field_api.php Diff File

MantisBT: master-1.2.x 9094a34d

2012-07-29 11:03

dregad


Details Diff
Custom field validation should pass when empty and min length > 0

Fix for 0012029 (commit 9c71d4f884200f682636e772cf3584202fc2443d)
introduced a regression in the validation of numeric custom fields when
the field's minimum length is greater than 0 and the data being
validated is empty. This prevents e.g. reporting of new issues with a
hidden custom field, or updating issues having a non-required, empty
field.

This commit resolves the problem by passing validation when the field is
empty. This should not cause problems for required fields, as that case
is covered by an earlier check in bug_report.php and bug_update.php.

Fixes 0014516
Affected Issues
0014516
mod - core/custom_field_api.php Diff File