fix: @jsii/python-runtime ValueError: Unknown interface#5213
Open
sgwilliams-ebsco wants to merge 2 commits into
Open
fix: @jsii/python-runtime ValueError: Unknown interface#5213sgwilliams-ebsco wants to merge 2 commits into
sgwilliams-ebsco wants to merge 2 commits into
Conversation
Includes new test in test_compliance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
This PR fixes an issue in the Python runtime where JSII raises a
ValueError: Unknown interfacewhen accessing a property with a union type that includes a behavioral interfaces and a struct. If the property is set to a known concrete type that implements the behavioral interface, JSII attempts to call_obtain_interfaceon the struct and raises an exception since the struct is not defined in the_interfacesMap.Context
When building a CDK aspect to check tags on the
aws_cdk.aws_ec2.CfnLaunchTemplate, I encountered an exception callingToken.is_unresolvedon thelaunch_template_dataproperty specifically when the property value is set to anIResolvable. I created a minimal example that reproduces the issue: https://github.com/sgwilliams-ebsco/jsii-unknown-interface-exampleThe exception is raised when accessing the property value instead of resolving to the correct concrete implementation (
aws_cdk.Intrinsicin this case).What's happening
In
resolve(self, kernel, ref), on line 164 of_reference_map.pyJSII attempts to build and return anInterfaceDynamicProxybased on the interfaces listed in theref:In
build_interface_proxies_for_ref(self, ref: ObjRef), the code calls_obtain_interface(fqn)for every interface listed inref.interfaces:But due to how union types are registered with JSII, the
ref.interfacescontains FQNs for Structs that are registered with_data_typesand not_interfaces. Calling_obtain_interfaceon those Structs leads to theValueError: Unknown interface.The fix is to filter out any FQNs in the
ref.interfaceswhen the FQN is registered with_data_types.More Info
I think there is a deeper issue with union types that is leading to Structs being listed in the
ref.interfacesin the first place. I researched that process but don't have the depth of understanding to attempt a fix at that level. I included my research in the unit test for this bug.Related
This PR is related to #5179.
AI Assistance Disclaimer
I used Claude Code to help me find and understand the source of the bug. However, all code changes were written by a human.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.