Skip to content

Commit

Permalink
[sdk/python] Fix invoke to handle empty dicts
Browse files Browse the repository at this point in the history
Make the hand-rolled invoke code resilient to `invoke` returning either `None` or an empty dict for empty results. This aligns all invokes with the same pattern as introduced by a907bdd.
  • Loading branch information
justinvp committed Nov 10, 2023
1 parent 579ea70 commit 270b37b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion provider/pkg/gen/python-templates/helm/v3/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,6 @@ def _parse_chart(all_config: Tuple[Union[ChartOpts, LocalChartOpts], pulumi.Reso

def invoke_helm_template(opts):
inv = pulumi.runtime.invoke('kubernetes:helm:template', {'jsonOpts': opts}, invoke_opts)
return inv.value['result'] if inv is not None and inv.value is not None else []
return (inv.value or {}).get('result', [])
objects = json_opts.apply(invoke_helm_template)
return objects.apply(lambda x: _parse_yaml_document(x, opts, transformations))
2 changes: 1 addition & 1 deletion provider/pkg/gen/python-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,4 @@ def _parse_yaml_object(

def invoke_yaml_decode(text, invoke_opts):
inv = pulumi.runtime.invoke('kubernetes:yaml:decode', {'text': text}, invoke_opts)
return inv.value['result'] if inv is not None and inv.value is not None else []
return (inv.value or {}).get('result', [])
2 changes: 1 addition & 1 deletion sdk/python/pulumi_kubernetes/helm/v3/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,6 @@ def _parse_chart(all_config: Tuple[Union[ChartOpts, LocalChartOpts], pulumi.Reso

def invoke_helm_template(opts):
inv = pulumi.runtime.invoke('kubernetes:helm:template', {'jsonOpts': opts}, invoke_opts)
return inv.value['result'] if inv is not None and inv.value is not None else []
return (inv.value or {}).get('result', [])
objects = json_opts.apply(invoke_helm_template)
return objects.apply(lambda x: _parse_yaml_document(x, opts, transformations))
2 changes: 1 addition & 1 deletion sdk/python/pulumi_kubernetes/yaml/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,4 +1949,4 @@ def _parse_yaml_object(

def invoke_yaml_decode(text, invoke_opts):
inv = pulumi.runtime.invoke('kubernetes:yaml:decode', {'text': text}, invoke_opts)
return inv.value['result'] if inv is not None and inv.value is not None else []
return (inv.value or {}).get('result', [])

0 comments on commit 270b37b

Please sign in to comment.