Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotating a transformation function results in error #1163

Closed
jmgilman opened this issue Jun 12, 2020 · 1 comment · Fixed by #1298
Closed

Annotating a transformation function results in error #1163

jmgilman opened this issue Jun 12, 2020 · 1 comment · Fixed by #1298
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec language/python
Milestone

Comments

@jmgilman
Copy link

Problem description

Annotating parameters in a transformation function results in an error.

Errors & Logs

error: Program failed with an unhandled exception:
    error: Traceback (most recent call last):
      File "/usr/local/bin/pulumi-language-python-exec", line 85, in <module>
        loop.run_until_complete(coro)
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
        return future.result()
      File "/Users/josh/code/lab/kube/venv/lib/python3.7/site-packages/pulumi/runtime/stack.py", line 81, in run_in_stack
        await run_pulumi_func(lambda: Stack(func))
      File "/Users/josh/code/lab/kube/venv/lib/python3.7/site-packages/pulumi/runtime/stack.py", line 34, in run_pulumi_func
        func()
      File "/Users/josh/code/lab/kube/venv/lib/python3.7/site-packages/pulumi/runtime/stack.py", line 81, in <lambda>
        await run_pulumi_func(lambda: Stack(func))
      File "/Users/josh/code/lab/kube/venv/lib/python3.7/site-packages/pulumi/runtime/stack.py", line 105, in __init__
        func()
      File "/usr/local/bin/pulumi-language-python-exec", line 84, in <lambda>
        coro = pulumi.runtime.run_in_stack(lambda: runpy.run_path(args.PROGRAM, run_name='__main__'))
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 280, in run_path
        run_name, mod_spec, pkg_name).copy()
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "./__main__.py", line 12, in <module>
        metallb = lb.MetalLB("loadbalancer", lb.MetalLBProperties.from_config(lb_config))
      File "./network/metallb.py", line 62, in __init__
        transformations=[_add_namespace])
      File "/Users/josh/code/lab/kube/venv/lib/python3.7/site-packages/pulumi_kubernetes/yaml.py", line 69, in __init__
        self.resources = _parse_yaml_document(__ret__, opts, transformations, resource_prefix)
      File "/Users/josh/code/lab/kube/venv/lib/python3.7/site-packages/pulumi_kubernetes/yaml.py", line 122, in _parse_yaml_document
        file_objects = _parse_yaml_object(obj, opts, transformations, resource_prefix)
      File "/Users/josh/code/lab/kube/venv/lib/python3.7/site-packages/pulumi_kubernetes/yaml.py", line 150, in _parse_yaml_object
        if len(getargspec(t)[0]) == 2:
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 1082, in getargspec
        raise ValueError("Function has keyword-only parameters or annotations"
    ValueError: Function has keyword-only parameters or annotations, use getfullargspec() API which can support them
    error: an unhandled error occurred: Program exited with non-zero exit code: 1

Affected product version(s)

pulumi-vault==2.2.0

Reproducing the issue

The issue can be reproduced by creating a transformation function and annotating the type as seen below:

def _add_namespace(obj: Any):
    obj['metadata']['namespace'] = 'metallb-system'

And then used somewhere as is shown below:

self.resources = yaml.ConfigFile('metallb-resources',
                                         URL,
                                         transformations=[_add_namespace])

Removing the Any annotation resolves the issue.

Suggestions for a fix

I'm not familiar with what is going on under the hood, and I understand that the type annotation, in this case, isn't necessarily required, but it seems like a resolvable bug given the descriptive help message given at the end.

@leezen leezen added the kind/bug Some behavior is incorrect or out of spec label Jun 12, 2020
@justinvp
Copy link
Member

justinvp commented Sep 9, 2020

This is a quick fix.

@justinvp justinvp self-assigned this Sep 9, 2020
@justinvp justinvp added this to the current milestone Sep 9, 2020
@leezen leezen modified the milestones: current, 0.44 Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec language/python
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants