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

jsii does not recognize an IDependable implementation written in Python #4396

Open
patelhpr opened this issue Jan 9, 2024 · 0 comments
Open
Labels
bug This issue is a bug. p1

Comments

@patelhpr
Copy link
Member

patelhpr commented Jan 9, 2024

Describe the bug

I am trying to create a python implementation of this function mentioned here in cdk. (https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L2293)

@jsii.implements(IDependable)
class CompositeDependable:
    def __init__(self):
        super().__init__()
        self.dependables = []

    @property
    def dependency_roots(self) -> List[IDependable]:
        ret: IDependable = []
        for dep in self.dependables:
            if isinstance(dep, IDependable):
                ret.extend(dep.dependency_roots)
            else:
                raise TypeError("All dependables must implement IDependable")
        return ret

    def add(self, dep: IDependable) -> None:
        self.dependables.append(dep)

When I run cdk synth I get this error

jsii.errors.JavaScriptError: 
  @jsii/kernel.RuntimeError: Error: [object Object] does not implement IDependable. Use "Dependable.implement()" to implement
      at Kernel._Kernel_ensureSync (/private/var/folders/dj/6xj1cj8d7vngc7vs39vg5xn40000gr/T/tmp8uxt9v8p/lib/program.js:10487:23)
      at Kernel.invoke (/private/var/folders/dj/6xj1cj8d7vngc7vs39vg5xn40000gr/T/tmp8uxt9v8p/lib/program.js:9851:102)
      at KernelHost.processRequest (/private/var/folders/dj/6xj1cj8d7vngc7vs39vg5xn40000gr/T/tmp8uxt9v8p/lib/program.js:11691:36)
      at KernelHost.run (/private/var/folders/dj/6xj1cj8d7vngc7vs39vg5xn40000gr/T/tmp8uxt9v8p/lib/program.js:11651:22)
      at Immediate._onImmediate (/private/var/folders/dj/6xj1cj8d7vngc7vs39vg5xn40000gr/T/tmp8uxt9v8p/lib/program.js:11652:46)
      at process.processImmediate (node:internal/timers:476:21)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/patelhpr/.pyenv/versions/3.10.9/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/patelhpr/.pyenv/versions/3.10.9/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/source/app.py", line 55, in <module>
    app.synth()
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/.venv/lib/python3.10/site-packages/aws_cdk/__init__.py", line 21164, in synth
    return typing.cast(_CloudAssembly_c693643e, jsii.invoke(self, "synth", [options]))
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/.venv/lib/python3.10/site-packages/jsii/_kernel/__init__.py", line 149, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/.venv/lib/python3.10/site-packages/jsii/_kernel/__init__.py", line 407, in invoke
    return _callback_till_result(self, response, InvokeResponse)
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/.venv/lib/python3.10/site-packages/jsii/_kernel/__init__.py", line 267, in _callback_till_result
    response = kernel.sync_complete(response.cbid, None, result, response_type)
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/.venv/lib/python3.10/site-packages/jsii/_kernel/__init__.py", line 445, in sync_complete
    return self.provider.sync_complete(
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/.venv/lib/python3.10/site-packages/jsii/_kernel/providers/process.py", line 403, in sync_complete
    resp = self._process.send(_CompleteRequest(complete=request), response_type)
  File "/Volumes/workplace/Connected-mobility-solution-on-aws/source/modules/acdp/backstage/cdk/.venv/lib/python3.10/site-packages/jsii/_kernel/providers/process.py", line 342, in send
    raise RuntimeError(resp.error) from JavaScriptError(resp.stack)
RuntimeError: Error: [object Object] does not implement IDependable. Use "Dependable.implement()" to implement

Expected Behavior

jsii should recognize this as a valid IDependable implementation

Current Behavior

jsii does not recognize it as an IDependable and throws an error

Reproduction Steps

Use the code given above in a cdk stack and run cdk synth.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

cdk version 2.115.0

Environment details (OS name and version, etc.)

MacOS 14.2.1

@patelhpr patelhpr added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 9, 2024
@mrgrain mrgrain added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Apr 9, 2024
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. p1
Projects
None yet
Development

No branches or pull requests

2 participants