Changes to extension-created field aren't written to DB from process_bug.cgi?

Matthew Bogosian mtb19 at columbia.edu
Tue Jan 15 07:27:16 UTC 2013


I think I've found the answer to my own question. There are basically two loops in process_bugs.cgi, one for regular fields and one for custom fields (line numbers are from 4.2.4):

    228 my @set_fields = qw(op_sys rep_platform priority bug_severity
    229                     component target_milestone version
    230                     bug_file_loc status_whiteboard short_desc
    231                     deadline remaining_time estimated_time
    232                     work_time set_default_assignee set_default_qa_contact
    233                     cclist_accessible reporter_accessible 
    234                     product confirm_product_change
    235                     bug_status resolution dup_id);
    236 push(@set_fields, 'assigned_to') if !$cgi->param('set_default_assignee');
    237 push(@set_fields, 'qa_contact')  if !$cgi->param('set_default_qa_contact');
    ...
    249 foreach my $field_name (@set_fields) {
    250     if (should_set($field_name, 1)) {
    251         my $param_name = $field_translation{$field_name} || $field_name;
    252         $set_all_fields{$param_name} = $cgi->param($field_name);
    253     }
    254 }
    ...
    338 my @custom_fields = Bugzilla->active_custom_fields;
    339 foreach my $field (@custom_fields) {
    340     my $fname = $field->name;
    341     if (should_set($fname, 1)) {
    342         $set_all_fields{$fname} = [$cgi->param($fname)];
    343     }
    344 }

Note that for the first loop (the non-custom fields), @set_fields is mostly hard-coded/fixed. There's no opportunity (that I can find) to change @set_fields before the loop executes. This seems a bit weird given the availability of the object_columns and object_update_columns hooks (i.e., that neither hook affects @set_fields). Does anyone know if this is intentional or if this is an oversight?

When I compare $bug->UPDATE_COLUMNS with @set_fields, I am reminded that fields names and column names may be different:

* assigned_to
  bug_file_loc
  bug_severity
  bug_status
  cclist_accessible
< component_id
> component
> confirm_product_change
  deadline
> dup_id
  estimated_time
< everconfirmed
  op_sys
  priority
< product_id
> product
* qa_contact
  remaining_time
  rep_platform
  reporter_accessible
  resolution
> set_default_assignee
> set_default_qa_contact
  short_desc
  status_whiteboard
  target_milestone
  version
> work_time

< = only in $bug->UPDATE_COLUMNS
> = only in @set_fields
* = in both, but optional in @set_fields

That being said, adding yet another hook to allow updating extension-added fields posted to process_bugs.cgi seems absurd. Does anyone have any suggestions on how to patch process_bugs.cgi to modify @set_fields in a sane way?

As always any guidance is appreciated.


    --Matt


On Jan 7, 2013, at 17:46, Matthew Bogosian wrote:

> In an extension, I have created a new field using the install_update_db hook. I've managed to get the new field into the DB by running checksetup.pl, and am able to display it for editing in show_bug.cgi using <template/en/default/hook/bug/edit-after_custom_fields.html.tmpl>.
> 
> However, whenever I try to set or change the value by submitting my changes (which get handed off to process_bugs.cgi as near as I can tell), the corresponding field is never updated. I have confirmed the new value is being passed to process_bugs.cgi as POST data when submitting the change from show_bugs.cgi.
> 
> I have implemented the object_columns and object_update_columns hooks as required, but they do not seem to have any effect:
> 
> #---- Extension.pm -------------------------------------------------------
> 
> ...
> 
> #=========================================================================                                                                    
> sub install_update_db {
>     my $dbh = Bugzilla->dbh;
> 
>     $dbh->bz_add_column('bugs', 'ip_thumb', {
>             TYPE => 'INT3',
>             REFERENCES => {
>                 TABLE  =>  'attachments',
>                 COLUMN => 'attach_id',
>                 DELETE => 'SET NULL'
>             }
>         });
> 
>     my $field = new Bugzilla::Field({ name => 'ip_thumb' });
> 
>     if (! $field) {
>         $field = Bugzilla::Field->create({
>                 buglist => 1,
>                 description => 'Thumbnail',
>                 name => 'ip_thumb',
>                 type => Bugzilla::Constants::FIELD_TYPE_FREETEXT,
>             });
>         $field->set_is_numeric(1);
>         $field->update();
>     }
> }
> 
> #=========================================================================                                                                    
> sub object_columns {
>     my ( $self, $args ) = @_;
>     my ( $class, $columns ) = @$args{qw(class columns)};
> 
>     if ($class->isa('Bugzilla::Bug')) {
>         push(@$columns, 'ip_thumb');
>     }
> }
> 
> #=========================================================================                                                                    
> sub object_update_columns {
>     my ( $self, $args ) = @_;
>     my ( $object, $columns ) = @$args{qw(object columns)};
> 
>     if ($object->isa('Bugzilla::Bug')) {
>         push(@$columns, 'ip_thumb');
>     }
> }
> 
> ...
> 
> What am I doing wrong? I'm running the extension on 4.2.4. I can't find any guidance from the Example extension, the API documentation, or any other source as to why my new value is not being updated. Any help would be greatly appreciated.
> 
> 
>     --Matt


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bugzilla.org/pipermail/developers/attachments/20130114/610b1b0a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4237 bytes
Desc: not available
URL: <http://lists.bugzilla.org/pipermail/developers/attachments/20130114/610b1b0a/attachment.p7s>


More information about the developers mailing list