aws / aws/jsii

jsii does not recognize an IDependable implementation written in Python

Open
#4,396 0 comments 0 reactions 0 assignees View on GitHub
bug p1
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### 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
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

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Python IDependable implementation from the issue and running cdk synth with CDK 2.115.0. Compare the behavior with the referenced CDK vpc.ts implementation and trace how jsii validates IDependable objects. Done means the reported Python implementation is accepted without the current runtime error, with a regression test covering the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.