[pve-devel] [PATCH common] Make returning undef possible

Thomas Lamprecht t.lamprecht at proxmox.com
Fri May 10 12:53:16 CEST 2019


On 5/10/19 12:42 PM, Dominic Jäger wrote:
> Returning undef as optional return value for API calls
> is now possible.
> 
> Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>

looks familiar ;-) As this is the _exact_ same hunk I sent you maybe
note this, not only to honor my contribution (which for such a thing
I do not care much), but to tell others which the persons are to
question about if this makes problems in the future, it's naturally
also OK for me if you already are familiar with CLIFormatter and/or
want to take the full blame ;-P Just as a notice if you take on other's
work in the future.

also the commit subject message is a bit to general and wrong.

How and  why does this make returning undef impossible? Maybe:

> print api result: ignore undefined data if result is optional

?

> ---
>  src/PVE/CLIFormatter.pm | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
> index e886db5..84dbed1 100644
> --- a/src/PVE/CLIFormatter.pm
> +++ b/src/PVE/CLIFormatter.pm
> @@ -413,6 +413,7 @@ sub print_api_result {
>  
>      if ($result_schema && defined($result_schema->{type})) {
>  	return if $result_schema->{type} eq 'null';
> +	return if $result_schema->{optional} && !defined($data);
>      } else {
>  	my $type = $guess_type->($data);
>  	$result_schema = { type => $type };
> 






More information about the pve-devel mailing list