You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/01/08 23:53:36 UTC

[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #4268: Fix Traffic Ops Perl endpoints to always be numbers

rawlinp commented on a change in pull request #4268: Fix Traffic Ops Perl endpoints to always be numbers
URL: https://github.com/apache/trafficcontrol/pull/4268#discussion_r364501167
 
 

 ##########
 File path: traffic_ops/app/lib/API/ServerCheck.pm
 ##########
 @@ -84,7 +84,7 @@ sub read {
 		$v->{revalPending}	= \$server->reval_pending;
 		foreach my $col (qw/aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar at au av aw ax ay az ba bb bc bd be bf/) {
 			if ( defined( $mapping{$col} ) && defined( $server->servercheck ) ) {
-				$v->{checks}->{ $mapping{$col} } = $server->servercheck->$col();
+				$v->{checks}->{ $mapping{$col} } = $server->servercheck->$col() + 0;
 
 Review comment:
   When I test this endpoint locally I now get the following warning hundreds of time (one for each server I'm guessing?):
   ```
   Use of uninitialized value in addition (+) at lib/API/ServerCheck.pm line 87
   ```
   If the column's value is null, this code converts it into 0, which might be a bad unintended consequence. I tried this out, and it seems to work (keeps the null values null but makes sure the integer values are actually integers not strings):
   ```
                   my $foo = $server->servercheck->$col();
   		if ( defined($foo) ) {
                       $foo = $foo + 0;
   		}
   		$v->{checks}->{ $mapping{$col} } = $foo;
   ```
   Don't you just love Perl? Can you try this out on your end and see if that works?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services