Closed Bug 466178 Opened 16 years ago Closed 10 years ago

Add an INTEGER custom field type

Categories

(Bugzilla :: Administration, task, P5)

Tracking

()

RESOLVED FIXED
Bugzilla 5.0

People

(Reporter: diego.prates, Assigned: mail)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 5 obsolete files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.18) Gecko/20081029 Firefox/2.0.0.18
Build Identifier: 3.2rc2

I've added a custom field to hold integer values, say, "Personal Order". So when I try to sort by that column in buglist, I get the following:

1
10
100
2
20
200

Buzilla sorts values as strings instead of integer values. Nevertheless, there is no place where I could specify the value as being integer instead of something else.

Fix suggestion: add a "Value Type" field so I can specify the value type on custom field creation; this can initially hold the major types as "string", "integer/numeric", "date", "boolean".

Note: not sure, but I think this won't happen for the numeric internal bugzilla column "ID". If true, a solution can come from there.

Note2: There is another bug possibly related to this one (but not exactly the same): 190206

Reproducible: Always

Steps to Reproduce:
1. Create a custom field
2. Fill some bugs with an integer value on it, just like the example in the summary (1, 10, 2, 20, 3, 30 ...)

Actual Results:  
Sort order is incorrect according to the expectation for integer values:
1
10
2
20

Expected Results:  
Expected numeric natural order:
1
2
10
20
Severity: normal → minor
OS: Windows XP → All
Hardware: PC → All
Version: unspecified → 3.2
If you're holding bug numbers, there's another field type for that. Otherwise, we're unlikely to fix this any time soon, though you could hack your DB to change the column to an int.
Priority: -- → P5
It's a numeric custom field. Could you please point me the table name/column name where I can hack the col type in the DB?

Thanks a lot
(In reply to Diego Prates from comment #2)
> It's a numeric custom field. Could you please point me the table name/column
> name where I can hack the col type in the DB?

It will be the cf_NAME in the bugs table.
brc have code that allows numeric and integer based custom fields. Are upstream interested in having it?
Flags: needinfo?
4-year anniversary in two weeks. Closing time?
Flags: needinfo?
(In reply to Diego Prates from comment #5)
> 4-year anniversary in two weeks. Closing time?

Not necessarily. brc have the code, and if upstream Bugzilla want it, we are happy to supply a patch. NEEDINFO is asking if upstream want a patch. If they don't, then this bug should be closed.

  -- simon
Flags: needinfo?
(In reply to Simon Green from comment #4)
> brc have code that allows numeric and integer based custom fields. Are
> upstream interested in having it?

yes, i think that would be excellent to have upstream.
Flags: needinfo?
Assignee: query-and-buglist → sgreen+mozilla
This is good news. Congrats to the team, great work.
Attached patch v1 patch (obsolete) — Splinter Review
Patch against trunk. I have only checked this works against MySQL v5. Checks should be made against the other database to make sure it doesn't break.

  -- simon
Attachment #679539 - Flags: review?(glob)
Comment on attachment 679539 [details] [diff] [review]
v1 patch

I honestly don't think we need these new field types at all. IMO, it's enough to let Bugzilla check that all values are numeric, and if it's the case, sort the list before displaying it.
Attachment #679539 - Flags: review?(glob) → review-
Assignee: sgreen+mozilla → query-and-buglist
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
Attachment #679539 - Attachment is obsolete: true
(In reply to Frédéric Buclin from comment #10)
> I honestly don't think we need these new field types at all. IMO, it's
> enough to let Bugzilla check that all values are numeric, and if it's the
> case, sort the list before displaying it.

In fact, all values have a sortkey, and so sortkeys should be used to sort columns. This would address this problem automatically, which is why I don't want new fields just to enter integers in them.
(In reply to Frédéric Buclin from comment #11)
> In fact, all values have a sortkey, and so sortkeys should be used to sort
> columns. This would address this problem automatically, which is why I don't
> want new fields just to enter integers in them.

can you please explain further how sortkeys can be used to order user entered data?

as per comment 0, if you have bugs with a string custom field that have the values:

1
10
100
2
20
200

where would you apply the sortkey, and what value would you use to sort these numerically?
I'm talking about drop-down custom fields. Values have a sortkey which can be used for sorting data.

For free text custom fields, it's easy for Perl to check if all values are numeric and do a numeric comparison when sorting the data.
Reopening.  Frédéric rejected Simon's patch, but did not indicate that another approach would be rejected either.

Frédéric, as far as I understood the code, Bugzilla lets the database handle sorting. Are you proposing to change that and add some post-processing to do numerical sorting inside Perl?
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: WONTFIX → ---
(In reply to Jens Bannmann from comment #15)
> Are you proposing to change that and add some post-processing to do
> numerical sorting inside Perl?

Yes. Currently, columns in buglists are sorted based on their sortkey when there is one. This includes custom fields. For custom free text fields, it should be easy to add some code in buglist.cgi (or Search.pm?) which detects if the column you want to use for sorting contains only numbers, and override the default sorting.
(In reply to Frédéric Buclin from comment #16)
> Yes. Currently, columns in buglists are sorted based on their sortkey when
> there is one. This includes custom fields. For custom free text fields, it
> should be easy to add some code in buglist.cgi (or Search.pm?) which detects
> if the column you want to use for sorting contains only numbers, and
> override the default sorting.

i don't think that's a good idea, as it would result in a column sorting differently based on the search results, resulting in inconsistent and unexpected ordering.  it would also be very inefficient, especially when dealing with large bug lists.

adding an integer custom field type fixes this issue at the correct place -- the database -- and provides the additional benefit of restricting numeric fields to just numeric data.  i'm disappointed that you've decided this isn't the right approach without any reasoning.
(In reply to Byron Jones ‹:glob› from comment #17)
> fields to just numeric data.  i'm disappointed that you've decided this
> isn't the right approach without any reasoning.

I gave the reasoning above.
Assignee: query-and-buglist → sgreen
Status: REOPENED → ASSIGNED
Attached patch v2 patch (obsolete) — Splinter Review
Updated patch.
Attachment #781382 - Flags: review?(glob)
Comment on attachment 781382 [details] [diff] [review]
v2 patch

As you were mentioning this patch on IRC, here is my review.


>=== modified file 'Bugzilla/Bug.pm'

>+use Regexp::Common;

I really think requiring a new Perl module for such a minor thing as validating integers and real numbers is overkill. It's trivial enough to write our own regexps for them. For integers, we already have detaint_signed() in Bugzilla::Util which does exactly that.


>+sub _check_integer_field {

You must also check that the integer is small enough, below MAX_INT_32, else PostgreSQL crashes:

DBD::Pg::db do failed: ERREUR:  la valeur « 2147483648 » est en dehors des limites du type integer



>+sub _check_numeric_field {

When I enter a very large number, such as 1234567890123456, PostgreSQL converts it into scientific notation 1.23456789012346e+15 and when reloading the bug, it's no longer possible to edit it because you get:

"The value '1.23456789012346e+15' in the Nombre décimal field is not a numeric value.".

So you must check that the value remains within some predefined limits.



>=== modified file 'Bugzilla/Field.pm'

>+    FIELD_TYPE_INTEGER,       { TYPE => 'INT4',  NOTNULL => 1, DEFAULT => 0 },
>+    FIELD_TYPE_NUMERIC,       { TYPE => 'FLOAT', NOTNULL => 1, DEFAULT => 0 },

The FLOAT type is undefined in the various DB/Schema/*.pm files and so you have no control on their real type. For instance, PostgreSQL converted FLOAT into "double precision" which uses 8 bytes. This may be what you want, but this must be explicit in the DB schema modules.
Attachment #781382 - Flags: review?(glob) → review-
Attached patch bug466178-v3.patch (obsolete) — Splinter Review
Fixes the issues in LpS's review. I've dropped support for floating number because it wasn't in the original request, not required for brc's needs, and requires some more investigation to work correctly.
Attachment #781382 - Attachment is obsolete: true
Attachment #8349175 - Flags: review?(glob)
Comment on attachment 8349175 [details] [diff] [review]
bug466178-v3.patch

Review of attachment 8349175 [details] [diff] [review]:
-----------------------------------------------------------------

this looks mostly good, just a few minor issues to address..

::: Bugzilla/Bug.pm
@@ +2119,5 @@
> +        return 0;
> +    }
> +
> +    my $orig_value = $value;
> +    if (! detaint_signed($value)) {

nit: remove space after !

@@ +2123,5 @@
> +    if (! detaint_signed($value)) {
> +        ThrowUserError("number_not_integer",
> +                       {field => $field, num => $orig_value});
> +    }
> +    elsif($value > MAX_INT_32) {

nit: add space after elsif

::: template/en/default/bug/field.html.tmpl
@@ +40,3 @@
>          <input id="[% field.name FILTER html %]" class="text_input"
>                 name="[% field.name FILTER html %]"
>                 value="[% value FILTER html %]" size="40"

for FIELD_TYPE_INTEGER add pattern="^\d+$"
(type="number" won't work as it accepts floats)

::: template/en/default/global/user-error.html.tmpl
@@ +1359,5 @@
> +  [% ELSIF error == "number_not_integer" %]
> +    [% title = "Integer Value Required" %]
> +    The value '[% num FILTER html %]' in the 
> +    <em>[% field_descs.$field FILTER html %]</em> field 
> +    is not an integer value (i.e. a whole number).

remove trailing whitespace
Attachment #8349175 - Flags: review?(glob) → review-
Attached patch bug466178-v4.patch (obsolete) — Splinter Review
TIL some HTML 5 :)
Attachment #8349175 - Attachment is obsolete: true
Attachment #8363450 - Flags: review?(glob)
Severity: minor → normal
Summary: [Sorting] Custom field sorts values incorrectly when holding integer values in buglist → Add an INTEGER custom field type
Comment on attachment 8363450 [details] [diff] [review]
bug466178-v4.patch

>=== modified file 'index.cgi'

>-      $dbh->selectrow_array('SELECT COUNT(*) FROM bugs WHERE assigned_to = ?
>-                             AND resolution = ""', undef, $user->id);
>+      $dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE assigned_to = ?
>+                             AND resolution = ''", undef, $user->id);

This is another bug.



>=== modified file 'template/en/default/bug/edit.html.tmpl'

>       [% PROCESS bug/field.html.tmpl value = bug.${field.name}
>-                                     editable = bug.check_can_change_field(field.name, 0, 1)
>+                                     editable = 1

Why this change? It shouldn't be editable if you are not allowed to edit it.
Attached patch bug466178-v5.patch (obsolete) — Splinter Review
Attachment #8363450 - Attachment is obsolete: true
Attachment #8363450 - Flags: review?(glob)
Attachment #8363960 - Flags: review?(glob)
(In reply to Byron Jones ‹:glob› from comment #22)
> for FIELD_TYPE_INTEGER add pattern="^\d+$"

You should simply write: pattern="\d+". The HTML5 specs says "the pattern attribute is matched against the entire value, not just any subset (somewhat as if it implied a ^(?: at the start of the pattern and a )$ at the end)."

Please fix that on checkin, for readability.
With the two character fix Frédéric suggested. If I don't fix it now, I'm likely to forget it by the time the code is reviewed and approved.

  -- simon
Attachment #8363960 - Attachment is obsolete: true
Attachment #8363960 - Flags: review?(glob)
Attachment #8364001 - Flags: review?(glob)
Comment on attachment 8364001 [details] [diff] [review]
bug466178-v5.patch

Review of attachment 8364001 [details] [diff] [review]:
-----------------------------------------------------------------

r=glob
Attachment #8364001 - Flags: review?(glob) → review+
Flags: approval?
Flags: approval? → approval+
Severity: normal → enhancement
Component: Query/Bug List → Administration
Keywords: relnote
Target Milestone: --- → Bugzilla 5.0
Committing to: bzr+ssh://bzr.mozilla.org/bugzilla/trunk/                       
modified Bugzilla/Bug.pm
modified Bugzilla/Constants.pm
modified Bugzilla/Field.pm
modified template/en/default/bug/field.html.tmpl
modified template/en/default/global/field-descs.none.tmpl
modified template/en/default/global/user-error.html.tmpl                       
Committed revision 8934.
Status: ASSIGNED → RESOLVED
Closed: 12 years ago10 years ago
Resolution: --- → FIXED
See Also: → 1031274
Blocks: 1031274
Added to relnotes for 5.0rc1.
Keywords: relnote
Blocks: 1198556
Blocks: 1198659
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: