View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0014516 | mantisbt | upgrade | public | 2012-07-26 07:30 | 2014-09-23 18:05 |
Reporter | PantsManUK | Assigned To | dregad | ||
Priority | low | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 1.2.11 | ||||
Target Version | 1.2.12 | Fixed in Version | 1.2.12 | ||
Summary | 0014516: 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. | ||||
Tags | No tags attached. | ||||
Attached Files | 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 | ||||
related to | 0012029 | closed | rombert | minimum length of custom fields of type numeric is not checked |
related to | 0015721 | closed | grangeway | Functionality to consider porting to master-2.0.x |
related to | 0014533 | closed | rombert | Port '14516: Custom field needs value when reporting following upgrade to 1.2.11' to the SOAP API |
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. |
|
What RDBMS are you using ? |
|
All pertinent data (and apologies for not including it originally Damien):- Host OS: Ubuntu 10.04 LTS |
|
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. |
|
Please test the attached patch and let me know how it goes |
|
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). |
|
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. |
|
(In reply to comment 0014516:0032399)
Thanks for the heads-up, Damien. 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
I guess it's done this way in order to return a differentiated error message to the user. |
|
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. |
|
Reminder sent to: dregad This introduces another issue. |
|
Thanks for testing, I'll have a look |
|
@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). |
|
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". |
|
(In reply to comment 0014516:0032408)
I've added bug 0014533 to track this for the SOAP API. |
|
@PantsManUK re 0014516:0032420:
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
Please try again with a standard MantisBT codebase and let me know if problem persists, if possible with detailed steps to reproduce. |
|
@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. |
|
Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch |
|
MantisBT: master c2d701e8 2012-07-29 11:03 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 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 |