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

Lazy still broken in Python #1781

Open
3 tasks
serverlessunicorn opened this issue Jul 9, 2020 · 4 comments
Open
3 tasks

Lazy still broken in Python #1781

serverlessunicorn opened this issue Jul 9, 2020 · 4 comments
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort language/python Related to Python bindings p1

Comments

@serverlessunicorn
Copy link

🐛 Bug Report

The following fails on CDK 1.49.1:
class Foo:
def produce(me, context):
return self.api.rest_api_id
lazy = core.Lazy.string_value(Foo())
with the error: AttributeError: type object 'Foo' has no attribute 'jsii_type'

Possibly recurrence or variant of 807 (#807)

Affected Languages

  • TypeScript or Javascript
  • [X ] Python
  • Java
  • .NET (C#, F#, ...)

General Information

  • JSII Version: CDK version is 1.49.1
  • Platform: Darwin MacBook-Pro.local 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64

What is the problem?

Lazy in AWS CDK Python appears to have a jsii serialization problem; see discussion in 807.

Verbose Log

Traceback (most recent call last):
File "deploy.py", line 80, in
deployer.deploy()
File "deploy.py", line 63, in deploy
cdk = cdkstack.CdkStack(scope=app, id='VendiaShareDeployer',
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/jsii/_runtime.py", line 66, in call
inst = super().call(*args, **kwargs)
File "/Users/timwagner/Desktop/projects/vendia/src/share/server/deploy/cdkstack.py", line 32, in init
lazy = core.Lazy.string_value(Foo())
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/aws_cdk/core/init.py", line 6313, in string_value
return jsii.sinvoke(cls, "stringValue", [producer, options])
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/jsii/_kernel/init.py", line 113, in wrapped
return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/jsii/_kernel/init.py", line 311, in sinvoke
args=_make_reference_for_native(self, args),
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/jsii/_kernel/init.py", line 124, in _make_reference_for_native
return [_make_reference_for_native(kernel, i) for i in d]
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/jsii/_kernel/init.py", line 124, in
return [_make_reference_for_native(kernel, i) for i in d]
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/jsii/_kernel/init.py", line 151, in _make_reference_for_native
kernel.create(d.class, d)
File "/Users/timwagner/Desktop/projects/vendia/src/share/venv/lib/python3.8/site-packages/jsii/_kernel/init.py", line 226, in create
fqn=klass.jsii_type or "Object",
AttributeError: type object 'Foo' has no attribute 'jsii_type'

@serverlessunicorn serverlessunicorn added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 9, 2020
@serverlessunicorn
Copy link
Author

Ah, so perhaps this is an AWS CDK issue: The example at https://docs.aws.amazon.com/cdk/latest/guide/tokens.html (with Python selected) fails as written, but if you use the example from #807 and add @jsii.implements(core.IStringProducer) as an annotation to the producing class, it succeeds with the workaround.

@SomayaB SomayaB added the language/python Related to Python bindings label Jul 9, 2020
@MrArnoldPalmer MrArnoldPalmer added effort/medium Medium work item – a couple days of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Aug 17, 2020
@MrArnoldPalmer MrArnoldPalmer removed their assignment Jun 28, 2021
@github-actions
Copy link
Contributor

This issue has not received any attention in 2 years. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 29, 2023
@github-actions github-actions bot closed this as completed Jul 5, 2023
@mschwab12
Copy link

This seems stil an issue. Can you reopen this bug?

@teemu-laakso
Copy link

I found a workaround for this bug. The following allows for synth time creation of any constructs with a callback:

class LazyCallback:
    __jsii_type__ = None

    def __init__(self, callback):
        self.callback = callback

    @jsii.member(jsii_name='produce')
    def produce(self, context):
        return self.callback()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort language/python Related to Python bindings p1
Projects
None yet
Development

No branches or pull requests

6 participants