Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the JIRA-Client CPAN distribution.


Subject: Ticket type not updated when calling JIRA::Client::update_issue
Date: Wed, 16 Nov 2011 17:34:27 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
Hello, I believe I found a bug in the update_issue() method of JIRA::Client. I have attached some test code and I am providing the output of my test run which should illustrate the bug. Basically when passing "type" into the hash to update the ticket the ticket type is not updated. Here is info about my working env and the module version being used: dbaber@atlas:~/src/blackjack/t$ perl -MJIRA::Client -e 'print "$JIRA::Client::VERSION\n"' 0.30 dbaber@atlas:~/src/blackjack/t$ perl -v This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi Copyright 1987-2009, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. dbaber@atlas:~/src/blackjack/t$ uname -a Linux atlas 2.6.32-35-generic #78-Ubuntu SMP Tue Oct 11 16:11:24 UTC 2011 x86_64 GNU/Linux dbaber@atlas:~/src/blackjack/t$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.04 DISTRIB_CODENAME=lucid DISTRIB_DESCRIPTION="Ubuntu 10.04.3 LTS" Here is the test run results: [11:32:15] t/Blackjack/jira_client_bug.t .. # Fixture: everything 1..10 ok 1 - instantiated JIRA::Client isa JIRA::Client ok 2 - instantiated RemoteIssue isa RemoteIssue ok 3 - ... issue assignee is 'dbaber' ok 4 - ... issue summary is 'TEST Ticket from Unit test' ok 5 - ... issue project is 'TESTPROJECT' ok 6 - ... issue type is '7' ok 7 - ... issue description is 'Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.' ok 8 - ... issue summary after update is 'TEST Ticket from Unit test- UPDATED' not ok 9 - ... issue type after update is '1' # Failed test '... issue type after update is '1'' # at t/Blackjack/jira_client_bug.t line 72. # got: '7' # expected: '1' ok 10 - ... issue description after update is 'UDATED - Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.' Failed 1/10 subtests [11:32:26] Test Summary Report ------------------- t/Blackjack/jira_client_bug.t (Wstat: 0 Tests: 10 Failed: 1) Failed test: 9 Files=1, Tests=10, 11 wallclock secs ( 0.04 usr 0.00 sys + 0.47 cusr 0.05 csys = 0.56 CPU) Result: FAIL And I have attached the code. Thanks, Dan -- Dan Baber | StreetLinks Lender Solutions | Software Developer 365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #72470] AutoReply: Ticket type not updated when calling JIRA::Client::update_issue
Date: Wed, 16 Nov 2011 23:13:21 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
After mucking about in the guts of this module I think it is JIRA's SOAP API itself that is not honoring changing the ticket type. sub AUTOLOAD { my ($self, @args) = @_; (my $method = $AUTOLOAD) =~ s/.*:://; say STDERR "AUTOLOAD = " . $AUTOLOAD if $method eq 'updateIssue'; say STDERR "Before madness, \@args = " . Dumper( \@args ) if $method eq 'updateIssue'; # Perform any non-default type coersion if (my $typeof = $typeof{$method}) { if (ref $typeof eq 'HASH') { while (my ($i, $type) = each %$typeof) { if (ref $type) { ref $type eq 'CODE' or croak "Invalid coersion spec to (", ref($type), ").\n"; $args[$i] = $type->($self, $args[$i]); } elsif (! ref $args[$i]) { $args[$i] = SOAP::Data->type($type => $args[$i]); } elsif (ref $args[$i] eq 'ARRAY') { foreach (@{$args[$i]}) { $_ = SOAP::Data->type($type => $_); } } elsif (ref $args[$i] eq 'HASH') { foreach (values %{$args[$i]}) { $_ = SOAP::Data->type($type => $_); } } else { croak "Can't coerse argument $i of method $AUTOLOAD.\n"; } } } elsif (ref $typeof eq 'CODE') { $typeof->($self, \$method, \@args); } } say STDERR "After madness, \@args = " . Dumper( \@args ) if $method eq 'updateIssue'; my $call = $self->{soap}->call($method, $self->{auth}, @args); croak $call->faultcode(), ', ', $call->faultstring() if defined $call->fault(); say STDERR "result = " . Dumper( $call->result() ) if $method eq 'updateIssue'; return $call->result(); } [17:05:06] t/Blackjack/jira_client_bug.t .. # Fixture: everything 1..10 ok 1 - instantiated JIRA::Client isa JIRA::Client ok 2 - instantiated RemoteIssue isa RemoteIssue ok 3 - ... issue assignee is 'dbaber' ok 4 - ... issue summary is 'TEST Ticket from Unit test' ok 5 - ... issue project is 'TESTPROJECT' ok 6 - ... issue type is '7' ok 7 - ... issue description is 'Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.' AUTOLOAD = JIRA::Client::updateIssue Before madness, @args = [ "TESTPROJECT-219", { description => "UDATED - Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.", summary => "TEST Ticket from Unit test- UPDATED", type => 1 } ] After madness, @args = [ "TESTPROJECT-219", [ bless( { id => "summary", values => [ "TEST Ticket from Unit test- UPDATED" ] }, 'RemoteFieldValue' ), bless( { id => "type", values => [ 1 ] }, 'RemoteFieldValue' ), bless( { id => "description", values => [ 1 ] }, 'RemoteFieldValue' ), bless( { id => "description", values => [ "UDATED - Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated." ] }, 'RemoteFieldValue' ) ] ] result = bless( { affectsVersions => [], assignee => "dbaber", attachmentNames => [], components => [], created => "2011-11-16T23:05:00.676Z", customFieldValues => [ bless( { customfieldId => "customfield_10002", key => undef, values => [ "2180000000.95" ] }, 'RemoteCustomFieldValue' ) ], description => "UDATED - Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.", duedate => undef, environment => undef, fixVersions => [], id => 15348, key => "TESTPROJECT-219", priority => 3, project => "TESTPROJECT", reporter => "integrations", resolution => undef, status => 1, summary => "TEST Ticket from Unit test- UPDATED", type => 7, updated => "2011-11-16T23:05:00.676Z", votes => 0 }, 'RemoteIssue' ) ok 8 - ... issue summary after update is 'TEST Ticket from Unit test- UPDATED' not ok 9 - ... issue type after update is '1' # Failed test '... issue type after update is '1'' # at t/Blackjack/jira_client_bug.t line 72. # got: '7' # expected: '1' ok 10 - ... issue description after update is 'UDATED - Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.' Failed 1/10 subtests [17:05:17] Test Summary Report ------------------- t/Blackjack/jira_client_bug.t (Wstat: 0 Tests: 10 Failed: 1) Failed test: 9 Files=1, Tests=10, 11 wallclock secs ( 0.04 usr 0.01 sys + 0.48 cusr 0.05 csys = 0.58 CPU) Result: FAIL Dan Show quoted text
----- Original Message ----- From: "Bugs in JIRA-Client via RT" <bug-JIRA-Client@rt.cpan.org> To: dbaber@corvisa.com Sent: Wednesday, November 16, 2011 11:34:42 AM Subject: [rt.cpan.org #72470] AutoReply: Ticket type not updated when calling JIRA::Client::update_issue Greetings, This message has been automatically generated in response to the creation of a trouble ticket regarding: "Ticket type not updated when calling JIRA::Client::update_issue", a summary of which appears below. There is no need to reply to this message right now. Your ticket has been assigned an ID of [rt.cpan.org #72470]. Your ticket is accessible on the web at: https://rt.cpan.org/Ticket/Display.html?id=72470 Please include the string: [rt.cpan.org #72470] in the subject line of all future correspondence about this issue. To do so, you may reply to this message. Thank you, bug-JIRA-Client@rt.cpan.org ------------------------------------------------------------------------- Hello, I believe I found a bug in the update_issue() method of JIRA::Client. I have attached some test code and I am providing the output of my test run which should illustrate the bug. Basically when passing "type" into the hash to update the ticket the ticket type is not updated. Here is info about my working env and the module version being used: dbaber@atlas:~/src/blackjack/t$ perl -MJIRA::Client -e 'print "$JIRA::Client::VERSION\n"' 0.30 dbaber@atlas:~/src/blackjack/t$ perl -v This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi Copyright 1987-2009, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. dbaber@atlas:~/src/blackjack/t$ uname -a Linux atlas 2.6.32-35-generic #78-Ubuntu SMP Tue Oct 11 16:11:24 UTC 2011 x86_64 GNU/Linux dbaber@atlas:~/src/blackjack/t$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.04 DISTRIB_CODENAME=lucid DISTRIB_DESCRIPTION="Ubuntu 10.04.3 LTS" Here is the test run results: [11:32:15] t/Blackjack/jira_client_bug.t .. # Fixture: everything 1..10 ok 1 - instantiated JIRA::Client isa JIRA::Client ok 2 - instantiated RemoteIssue isa RemoteIssue ok 3 - ... issue assignee is 'dbaber' ok 4 - ... issue summary is 'TEST Ticket from Unit test' ok 5 - ... issue project is 'TESTPROJECT' ok 6 - ... issue type is '7' ok 7 - ... issue description is 'Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.' ok 8 - ... issue summary after update is 'TEST Ticket from Unit test- UPDATED' not ok 9 - ... issue type after update is '1' # Failed test '... issue type after update is '1'' # at t/Blackjack/jira_client_bug.t line 72. # got: '7' # expected: '1' ok 10 - ... issue description after update is 'UDATED - Test ticket to illustrate bug in JIRA::Client where the ticket type is not updated.' Failed 1/10 subtests [11:32:26] Test Summary Report ------------------- t/Blackjack/jira_client_bug.t (Wstat: 0 Tests: 10 Failed: 1) Failed test: 9 Files=1, Tests=10, 11 wallclock secs ( 0.04 usr 0.00 sys + 0.47 cusr 0.05 csys = 0.56 CPU) Result: FAIL And I have attached the code. Thanks, Dan -- Dan Baber | StreetLinks Lender Solutions | Software Developer 365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com -- Dan Baber | StreetLinks Lender Solutions | Software Developer 2365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com

Message body is not shown because it is too large.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #72470] AutoReply: Ticket type not updated when calling JIRA::Client::update_issue
Date: Thu, 17 Nov 2011 08:13:30 -0200
To: bug-JIRA-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
2011/11/16 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org> Show quoted text
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > After mucking about in the guts of this module I think it is JIRA's SOAP > API itself that is not honoring changing the ticket type. >
Hi Dan. Please, confirm that the "Issue Type" field is added to your edit screen. If it's not this is precisely the behaviour you would see, as I understand from this <http://forums.atlassian.com/thread.jspa?messageID=257314110>. -- Gustavo
Subject: Re: [rt.cpan.org #72470] AutoReply: Ticket type not updated when calling JIRA::Client::update_issue
Date: Thu, 17 Nov 2011 15:15:52 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
I can update the issue type for tickets using the account that our system creates the tickets as. That does not appear to be a problem for me. I see "Issue Type" on the edit screen and I am able to change it and save it. Show quoted text
----- Original Message ----- From: "Gustavo Leite de Mendonça Chaves via RT" <bug-JIRA-Client@rt.cpan.org> To: dbaber@corvisa.com Sent: Thursday, November 17, 2011 4:13:43 AM Subject: Re: [rt.cpan.org #72470] AutoReply: Ticket type not updated when calling JIRA::Client::update_issue <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > 2011/11/16 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org>
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > After mucking about in the guts of this module I think it is JIRA's SOAP > API itself that is not honoring changing the ticket type. >
Hi Dan. Please, confirm that the "Issue Type" field is added to your edit screen. If it's not this is precisely the behaviour you would see, as I understand from this <http://forums.atlassian.com/thread.jspa?messageID=257314110>. -- Gustavo -- Dan Baber | StreetLinks Lender Solutions | Software Developer 2365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #72470] AutoReply: Ticket type not updated when calling JIRA::Client::update_issue
Date: Sat, 19 Nov 2011 18:41:57 -0200
To: bug-JIRA-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
2011/11/17 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org> Show quoted text
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > I can update the issue type for tickets using the account that our system > creates the tickets as. That does not appear to be a problem for me. I see > "Issue Type" on the edit screen and I am able to change it and save it.
You're right. I found out that this is due to this issue: https://jira.atlassian.com/browse/JRA-12300. Some fields in JIRA must be named one way when you set them but are named otherwise when you get them from JIRA. I knew about "affectVersions" which must be named "versions" when set and I had special code to deal with it in JIRA::Client. Now I learned that "type" is another case. It must be named "issuetype" when you set it. Try it. I'm going to generalize the code I have in JIRA::Client to deal with any number of such cases. I don't know of any other, but there might be some more. I'll let you know when I release it. Thank you for the report. -- Gustavo.
Dan, I've just released JIRA::Client 0.31 which should solve the problem. Now you can call the field 'type' or 'issuetype' and both should work. The same problem affects the field 'affectVersions' which can be called 'versions' also. Please, try it out. Thanks. Gustavo.
Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Mon, 21 Nov 2011 17:29:23 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
Things seem to work except when trying to loop through the keys in my hash and compare values. My tests were failing because the input hash that was passed by reference got modified and the issue object did not contain the 'issuetype' key (I would assume you'd have the same problem with the affectVersions -> versions translation). The existing type key is also removed from the input params hash which caused failures. Test code snippet: <snip> my %update_attrs = ( type => 'Bug', summary => $attrs{summary} . "- UPDATED", description => "UDATED - " . $attrs{description}, ); $issue = $client->update_issue( $issue, \%update_attrs ); #say STDERR "######DEBUG> issue = " . Dumper( $issue ); #say STDERR "######DEBUG> \%update_attrs = " . Dumper( \%update_attrs ); foreach my $attr ( keys %update_attrs ) { is $issue->{$attr}, $update_attrs{$attr}, "... issue $attr after update is '$update_attrs{$attr}'"; } I made this modification to the code in Client.pm: --- Client.pm.old 2011-11-19 14:49:43.000000000 -0600 +++ Client.pm 2011-11-21 11:27:52.946685770 -0600 @@ -490,9 +490,9 @@ # Due to a bug in JIRA we have to substitute the names of some fields. foreach my $field (keys %JRA12300) { - if (my $value = delete $params->{$field}) { - $params->{$JRA12300{$field}} = $value; - } + if (my $value = $params->{$field}) { + $params->{$JRA12300{$field}} = $value; + } } # Expand the custom_fields hash into the custom fields themselves. @@ -502,7 +502,14 @@ } } - return $self->updateIssue($key, $params); + $issue = $self->updateIssue($key, $params); + + # Scrub renamed fields out of the input hash after update + foreach my $key ( keys %JRA12300 ) { + delete $params->{ $JRA12300{$key} }; + } + + return $issue; } =item B<get_issue_types> so that my test code would pass. I was assuming that we don't want to modify the input hash on the calling code, do we? I attached the diff file as well. Dan Show quoted text
----- Original Message ----- From: "Gustavo Leite de Mendonça Chaves via RT" <bug-JIRA-Client@rt.cpan.org> To: dbaber@corvisa.com Sent: Saturday, November 19, 2011 3:00:50 PM Subject: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > Dan, I've just released JIRA::Client 0.31 which should solve the problem. Now you can call the field 'type' or 'issuetype' and both should work. The same problem affects the field 'affectVersions' which can be called 'versions' also. Please, try it out. Thanks. Gustavo. -- Dan Baber | StreetLinks Lender Solutions | Software Developer 2365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Mon, 21 Nov 2011 18:03:43 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
Or you can make a copy of the params and modify them to your heart's content? --- Client.pm.old 2011-11-19 14:49:43.000000000 -0600 +++ Client.pm 2011-11-21 12:00:10.236134752 -0600 @@ -471,38 +471,40 @@ my ($project) = ($key =~ /^([^-]+)/); + my $params_copy = { %$params }; + # Convert some fields' values - foreach my $field (grep {exists $_converters{$_}} keys %$params) { - $_converters{$field}->($self, $params, $field, $project); + foreach my $field (grep {exists $_converters{$_}} keys %$params_copy) { + $_converters{$field}->($self, $params_copy, $field, $project); } # Convert RemoteComponent objects into component ids - if (my $comps = $params->{components}) { + if (my $comps = $params_copy->{components}) { $_ = $_->{id} foreach @$comps; } # Convert RemoteVersion objects into version ids for my $field (qw/fixVersions affectsVersions/) { - if (my $versions = $params->{$field}) { + if (my $versions = $params_copy->{$field}) { $_ = $_->{id} foreach @$versions; } } # Due to a bug in JIRA we have to substitute the names of some fields. foreach my $field (keys %JRA12300) { - if (my $value = delete $params->{$field}) { - $params->{$JRA12300{$field}} = $value; - } + if (my $value = $params_copy->{$field}) { + $params_copy->{$JRA12300{$field}} = $value; + } } # Expand the custom_fields hash into the custom fields themselves. - if (my $custom_fields = delete $params->{custom_fields}) { + if (my $custom_fields = delete $params_copy->{custom_fields}) { while (my ($id, $values) = each %$custom_fields) { - $params->{$id} = $values; + $params_copy->{$id} = $values; } } - return $self->updateIssue($key, $params); + return $self->updateIssue($key, $params_copy); } =item B<get_issue_types> I had to fix the mapping in my test code because 1 != 'Bug': my %update_attrs = ( type => 'Bug', summary => $attrs{summary} . "- UPDATED", description => "UDATED - " . $attrs{description}, ); $issue = $client->update_issue( $issue, \%update_attrs ); #say STDERR "######DEBUG> issue = " . Dumper( $issue ); #say STDERR "######DEBUG> \%update_attrs = " . Dumper( \%update_attrs ); foreach my $attr ( keys %update_attrs ) { my $val = $issue->{$attr}; $val = $TYPES->{ $issue->{$attr} } if $attr =~ /type/; is $val, $update_attrs{$attr}, "... issue $attr after update is '$update_attrs{$attr}'"; } Either way works I guess. I don't know if your intention is to not modify the input hash or what. Show quoted text
----- Original Message ----- From: "Gustavo Leite de Mendonça Chaves via RT" <bug-JIRA-Client@rt.cpan.org> To: dbaber@corvisa.com Sent: Saturday, November 19, 2011 3:00:50 PM Subject: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > Dan, I've just released JIRA::Client 0.31 which should solve the problem. Now you can call the field 'type' or 'issuetype' and both should work. The same problem affects the field 'affectVersions' which can be called 'versions' also. Please, try it out. Thanks. Gustavo. -- Dan Baber | StreetLinks Lender Solutions | Software Developer 2365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com

Message body is not shown because it is too large.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Mon, 21 Nov 2011 23:50:21 -0200
To: bug-JIRA-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
2011/11/21 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org> Show quoted text
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > Things seem to work except when trying to loop through the keys in my hash > and compare values. My tests were failing because the input hash that was > passed by reference got modified and the issue object did not contain the > 'issuetype' key (I would assume you'd have the same problem with the > affectVersions -> versions translation). The existing type key is also > removed from the input params hash which caused failures. >
I see. I have to confess that I've never given a second thought to the need to preserve the hash's keys. The hash's values must be modified but I can see value in preserving the hash's keys. Please, tell me what you thing of the attached patch. It tries to preserve the params hash's keys in the functions create_issue, update_issue, and progress_workflow_action_safely. It also documents the need to modify the hash's values and the preservation of its keys. If it's good I'll make another release. Thank you. Gustavo.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Tue, 22 Nov 2011 16:13:57 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
You know the more I think about it the more I say we stick w/ what's in 0.31 and I can just pass a copy of my hash in like so { %hash } because all your docs say pass a literal hashref w/ the proper key/val pairs. Besides, this patch doesn't work for create_issue ;P. I got a SOAP error back from the server complaining about issuetype which I worked around by just commenting out the 2 foreach loops. Let's just go with 0.31 and not bother hacking anything else. Dan Show quoted text
----- Original Message ----- From: "Gustavo Leite de Mendonça Chaves via RT" <bug-JIRA-Client@rt.cpan.org> To: dbaber@corvisa.com Sent: Monday, November 21, 2011 7:50:37 PM Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > 2011/11/21 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org>
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > Things seem to work except when trying to loop through the keys in my hash > and compare values. My tests were failing because the input hash that was > passed by reference got modified and the issue object did not contain the > 'issuetype' key (I would assume you'd have the same problem with the > affectVersions -> versions translation). The existing type key is also > removed from the input params hash which caused failures. >
I see. I have to confess that I've never given a second thought to the need to preserve the hash's keys. The hash's values must be modified but I can see value in preserving the hash's keys. Please, tell me what you thing of the attached patch. It tries to preserve the params hash's keys in the functions create_issue, update_issue, and progress_workflow_action_safely. It also documents the need to modify the hash's values and the preservation of its keys. If it's good I'll make another release. Thank you. Gustavo. [Text Documents:Client.pm.patch] -- Dan Baber | StreetLinks Lender Solutions | Software Developer 2365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com

Message body is not shown because sender requested not to inline it.

diff --git a/lib/JIRA/Client.pm b/lib/JIRA/Client.pm index e3ed635..75d0df3 100644 --- a/lib/JIRA/Client.pm +++ b/lib/JIRA/Client.pm @@ -400,50 +400,69 @@ You can do it like this: {customfield_10011 => {'0' => 10031, '1' => 10188}}, +Note that the hash's values will be modified to make them comply to +JIRA's data requirements. However, the hash's keys will be preserved. =cut sub create_issue { - my ($self, $hash, $seclevel) = @_; + my ($self, $params, $seclevel) = @_; croak "create_issue requires an argument.\n" - unless defined $hash; + unless defined $params; croak "create_issue's argument must be a HASH ref.\n" - unless ref $hash && ref $hash eq 'HASH'; + unless ref $params && ref $params eq 'HASH'; for my $field (qw/project summary type/) { croak "create_issue's HASH ref must define a '$field'.\n" - unless exists $hash->{$field}; + unless exists $params->{$field}; } # Convert some fields' values - foreach my $field (grep {exists $_converters{$_}} keys %$hash) { - $_converters{$field}->($self, $hash, $field, $hash->{project}); + foreach my $field (grep {exists $_converters{$_}} keys %$params) { + $_converters{$field}->($self, $params, $field, $params->{project}); } # Substitute customFieldValues for custom_fields - if (my $cfs = delete $hash->{custom_fields}) { - $hash->{customFieldValues} = [map {RemoteCustomFieldValue->new($_, $cfs->{$_})} keys %$cfs]; + if (my $cfs = delete $params->{custom_fields}) { + $params->{customFieldValues} = [map {RemoteCustomFieldValue->new($_, $cfs->{$_})} keys %$cfs]; + } + + # Due to a bug in JIRA we have to substitute the names of some fields. + foreach my $field (grep {exists $params->{$_}} keys %JRA12300) { + $params->{$JRA12300{$field}} = delete $params->{$field}; } - if (my $parent = delete $hash->{parent}) { + my $issue; + + if (my $parent = delete $params->{parent}) { if (defined $seclevel) { - return $self->createIssueWithParentWithSecurityLevel($hash, _convert_security_level($self, $parent, $seclevel)); + $issue = $self->createIssueWithParentWithSecurityLevel($params, _convert_security_level($self, $parent, $seclevel)); } else { - return $self->createIssueWithParent($hash, $parent); + $issue = $self->createIssueWithParent($params, $parent); } } else { if (defined $seclevel) { - return $self->createIssueWithSecurityLevel($hash, _convert_security_level($self, $seclevel)); + $issue = $self->createIssueWithSecurityLevel($params, _convert_security_level($self, $seclevel)); } else { - return $self->createIssue($hash); + $issue = $self->createIssue($params); } } + + # Restore substituted field names in hash passed by reference + foreach my $field (grep {exists $params->{$_}} keys %JRA12300_backwards) { + $params->{$JRA12300_backwards{$field}} = delete $params->{$field}; + } + + return $issue; } =item B<update_issue> ISSUE_OR_KEY, HASH_REF Update a issue given a hash containing the values for its fields. The -first argument may be an issue key or a RemoteIssue object. +first argument may be an issue key or a RemoteIssue object. The second +argument must be a hash-ref specifying the fields's values just like +documented in the create_issue function above. In particular, note +that its values will be modified, but not its keys. This is an easier to use version of the updateIssue API method because it accepts the same shortcuts that create_issue does. @@ -489,10 +508,8 @@ sub update_issue } # Due to a bug in JIRA we have to substitute the names of some fields. - foreach my $field (keys %JRA12300) { - if (my $value = delete $params->{$field}) { - $params->{$JRA12300{$field}} = $value; - } + foreach my $field (grep {exists $params->{$_}} keys %JRA12300) { + $params->{$JRA12300{$field}} = delete $params->{$field}; } # Expand the custom_fields hash into the custom fields themselves. @@ -502,7 +519,14 @@ sub update_issue } } - return $self->updateIssue($key, $params); + $issue = $self->updateIssue($key, $params); + + # Restore substituted field names in hash passed by reference + foreach my $field (grep {exists $params->{$_}} keys %JRA12300_backwards) { + $params->{$JRA12300_backwards{$field}} = delete $params->{$field}; + } + + return $issue; } =item B<get_issue_types> @@ -760,8 +784,9 @@ returned by a previous call to, e.g., C<getIssue>. =item C<ACTION> can be either an action I<id> or an action I<name>. =item C<PARAMS> must be a hash mapping field names to field -values. This hash accepts the same shortcuts as the argument to -B<create_issue>. +values. This hash is treated in the same way as the hash passed to the +function B<create_issue> above. In particular, note that its values +will be modified, but not its keys. =back @@ -780,11 +805,15 @@ And risking to forget to pass some field you can do this: =cut sub progress_workflow_action_safely { - my ($self, $key, $action, $params) = @_; - my $issue; - if (ref $key) { - $issue = $key; + my ($self, $issue, $action, $params) = @_; + my $key; + if (ref $issue) { + croak "progress_workflow_action_safely's first argument must be a RemoteIssue reference.\n" + unless ref $key eq 'RemoteIssue'; $key = $issue->{key}; + } else { + $key = $issue; + $issue = undef; } my ($project) = (split /-/, $key)[0]; $params = {} unless defined $params; @@ -846,10 +875,8 @@ sub progress_workflow_action_safely { } # Due to a bug in JIRA we have to substitute the names of some fields. - foreach my $field (keys %JRA12300) { - if (my $value = delete $params->{$field}) { - $params->{$JRA12300{$field}} = $value; - } + foreach my $field (grep {exists $params->{$_}} keys %JRA12300) { + $params->{$JRA12300{$field}} = delete $params->{$field}; } # Expand the custom_fields hash into the custom fields themselves. @@ -859,7 +886,14 @@ sub progress_workflow_action_safely { } } - return $self->progressWorkflowAction($key, $action, $params); + $issue = $self->progressWorkflowAction($key, $action, $params); + + # Restore substituted field names in hash passed by reference + foreach my $field (grep {exists $params->{$_}} keys %JRA12300_backwards) { + $params->{$JRA12300_backwards{$field}} = delete $params->{$field}; + } + + return $issue; } =item B<get_issue_custom_field_values> ISSUE, NAME_OR_IDs
Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Sat, 26 Nov 2011 00:51:12 -0200
To: bug-JIRA-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
2011/11/22 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org> Show quoted text
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > You know the more I think about it the more I say we stick w/ what's in > 0.31 and I can just pass a copy of my hash in like so { %hash } because all > your docs say pass a literal hashref w/ the proper key/val pairs. Besides, > this patch doesn't work for create_issue ;P. I got a SOAP error back from > the server complaining about issuetype which I worked around by just > commenting out the 2 foreach loops. Let's just go with 0.31 and not bother > hacking anything else. >
Not so fast. :-) I performed a serious refactoring in all the conversion code necessary for create_issue, update_issue and progress_workflow_action_safely. I tested it agains Atlassian's OnDemand JIRA Demo ( http://sandbox.onjira.com/browse/TST-2551) and I was able to create and to progress an issue correctly. The hashes passed to those three methods are completely preserved now. I decided to construct new ones instead of performing the necessary conversions in the argument. This makes the code cleaner and is saner to the programmer, I guess. Would you care to check it one more time? I'm attaching the file and not the patch because the later is half the size of the former. -- Gustavo.
Download Client.pm.gz
application/x-gzip 12.4k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Mon, 28 Nov 2011 16:31:24 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
I have no idea how this works for you, there was an infinite loop in _convert_params: # Convert fields' values while (my ($field, $value) = %$params) { $converted{$field} = exists $_converters{$field} ? $_converters{$field}->($self, $value, $project) : $value; } I changed it to (added each before the %$params): # Convert fields' values while (my ($field, $value) = each %$params) { $converted{$field} = exists $_converters{$field} ? $_converters{$field}->($self, $value, $project) : $value; } and JIRA still yells at me w/ this error: soapenv:Server.userException, org.xml.sax.SAXException: Invalid element in com.atlassian.jira.rpc.soap.beans.RemoteIssue - issuetype at /home/dbaber/src/blackjack/script/../lib/Blackjack/JIRA.pm line 373 soapenv:Server.userException, org.xml.sax.SAXException: Invalid element in com.atlassian.jira.rpc.soap.beans.RemoteIssue - issuetype at /home/dbaber/src/blackjack/script/../lib/Blackjack/JIRA.pm line 373 ...caught at /home/dbaber/src/blackjack/script/../lib/Persistent/Blackjack.pm line 156. I am not getting the same result(s) as you are. Dan ----- Original Message ----- From: "Gustavo Leite de Mendonça Chaves via RT" <bug-JIRA-Client@rt.cpan.org> To: dbaber@corvisa.com Sent: Friday, November 25, 2011 8:51:24 PM Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > 2011/11/22 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org> Show quoted text
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > You know the more I think about it the more I say we stick w/ what's in > 0.31 and I can just pass a copy of my hash in like so { %hash } because all > your docs say pass a literal hashref w/ the proper key/val pairs. Besides, > this patch doesn't work for create_issue ;P. I got a SOAP error back from > the server complaining about issuetype which I worked around by just > commenting out the 2 foreach loops. Let's just go with 0.31 and not bother > hacking anything else. >
Not so fast. :-) I performed a serious refactoring in all the conversion code necessary for create_issue, update_issue and progress_workflow_action_safely. I tested it agains Atlassian's OnDemand JIRA Demo ( http://sandbox.onjira.com/browse/TST-2551) and I was able to create and to progress an issue correctly. The hashes passed to those three methods are completely preserved now. I decided to construct new ones instead of performing the necessary conversions in the argument. This makes the code cleaner and is saner to the programmer, I guess. Would you care to check it one more time? I'm attaching the file and not the patch because the later is half the size of the former. -- Gustavo. -- Dan Baber | StreetLinks Lender Solutions | Software Developer 2365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com
Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Tue, 29 Nov 2011 23:10:15 -0200
To: bug-JIRA-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
2011/11/28 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org> Show quoted text
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > I have no idea how this works for you, there was an infinite loop in > _convert_params: >
I'm sorry. I think I got caught again by the prove command. I tend to forget to pass the -b option to it and then it uses the installed JIRA::Client in my system in the tests. I saw the missing 'each' but there are other errors. It seems that the field name convertion must be performed when calling updateIssue and progressWorkflowAction but not on createIssue. I'll check and work on this over the weekend. Thank you. BTW, I saw your other ticket (rt72667) and fixed it in my git repository. I'll try to have them both fixed for the next release. Gustavo.
Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Mon, 5 Dec 2011 23:22:14 -0200
To: bug-JIRA-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
Dan, I've just released JIRA::Client 0.32. It should fix both rt72470<https://rt.cpan.org/Public/Bug/Display.html?id=72470> and rt72667 <https://rt.cpan.org/Ticket/Display.html?id=72667>. Please, give it a try. Gustavo.
Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Tue, 6 Dec 2011 18:09:32 +0000 (UTC)
To: bug-JIRA-Client [...] rt.cpan.org
From: Dan Baber <dbaber [...] corvisa.com>
Everything seems to be working accept update_issue was failing w/ # soapenv:Server.userException, org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize. I did some digging and the affectsVersion was not being flattened until I changed this in _flaten_components_and_versions(): --- Client.pm.orig 2011-12-06 12:04:54.616137832 -0600 +++ Client.pm 2011-12-06 12:09:39.036977299 -0600 @@ -388,7 +388,7 @@ my ($params) = @_; # Flaten Component and Version fields - for my $field (grep {exists $params->{$_}} qw/components versions fixVersions/) { + for my $field (grep {exists $params->{$_}} qw/components affectsVersions fixVersions/) { $params->{$field} = [map {$_->{id}} @{$params->{$field}}]; } This gets changed to 'versions' a few lines after that when you do the JRA12300 field name conversion. Dan ----- Original Message ----- From: "Gustavo Leite de Mendonça Chaves via RT" <bug-JIRA-Client@rt.cpan.org> To: dbaber@corvisa.com Sent: Monday, December 5, 2011 7:22:24 PM Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > Dan, I've just released JIRA::Client 0.32. It should fix both rt72470<https://rt.cpan.org/Public/Bug/Display.html?id=72470> and rt72667 <https://rt.cpan.org/Ticket/Display.html?id=72667>. Please, give it a try. Gustavo. -- Dan Baber | StreetLinks Lender Solutions | Software Developer 2365 N. Mayfair Road, Second Floor, Milwaukee, WI 53226 www.streetlinks.com | dbaber@corvisa.com

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #72470] Ticket type not updated when calling JIRA::Client::update_issue
Date: Tue, 6 Dec 2011 19:46:35 -0200
To: bug-JIRA-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
2011/12/6 Dan Baber via RT <bug-JIRA-Client@rt.cpan.org> Show quoted text
> Queue: JIRA-Client > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=72470 > > > Everything seems to be working accept update_issue was failing w/ > > > # soapenv:Server.userException, org.xml.sax.SAXException: > SimpleDeserializer encountered a child element, which is NOT expected, in > something it was trying to deserialize. > > I did some digging and the affectsVersion was not being flattened until I > changed this in _flaten_components_and_versions(): >
Thank you, Dan. I'll fix this in a new release, hopefully with a solution to the duedate problem too. Gustavo.
Fixed in v0.33.