Skip to content

Commit eec9640

Browse files
committed
fix(python): dynamic proxies handling of setters
The Dyanmic proxies were missing an implementation of `__setattr__`, which caused setter invokations to not be forwarded to the `node` process. This is what causes aws/aws-cdk#5032
1 parent a820217 commit eec9640

16 files changed

Lines changed: 516 additions & 4 deletions

File tree

packages/jsii-calc/lib/compliance.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,3 +2266,32 @@ export class Demonstrate982 {
22662266

22672267
public constructor() { }
22682268
}
2269+
2270+
/**
2271+
* Make sure that setters are properly called on objects with interfaces
2272+
*/
2273+
export interface IObjectWithProperty {
2274+
property: string;
2275+
wasSet(): boolean;
2276+
}
2277+
export class ObjectWithPropertyProvider {
2278+
public static provide(): IObjectWithProperty {
2279+
class Impl implements IObjectWithProperty {
2280+
private _property: string = '';
2281+
private _wasSet = false;
2282+
2283+
public get property() { return this._property; }
2284+
public set property(value: string) {
2285+
this._property = value;
2286+
this._wasSet = true;
2287+
}
2288+
2289+
public wasSet() {
2290+
return this._wasSet;
2291+
}
2292+
}
2293+
return new Impl();
2294+
}
2295+
2296+
private constructor() { }
2297+
}

packages/jsii-calc/test/assembly.jsii

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5118,6 +5118,54 @@
51185118
}
51195119
]
51205120
},
5121+
"jsii-calc.IObjectWithProperty": {
5122+
"assembly": "jsii-calc",
5123+
"docs": {
5124+
"stability": "experimental",
5125+
"summary": "Make sure that setters are properly called on objects with interfaces."
5126+
},
5127+
"fqn": "jsii-calc.IObjectWithProperty",
5128+
"kind": "interface",
5129+
"locationInModule": {
5130+
"filename": "lib/compliance.ts",
5131+
"line": 2273
5132+
},
5133+
"methods": [
5134+
{
5135+
"abstract": true,
5136+
"docs": {
5137+
"stability": "experimental"
5138+
},
5139+
"locationInModule": {
5140+
"filename": "lib/compliance.ts",
5141+
"line": 2275
5142+
},
5143+
"name": "wasSet",
5144+
"returns": {
5145+
"type": {
5146+
"primitive": "boolean"
5147+
}
5148+
}
5149+
}
5150+
],
5151+
"name": "IObjectWithProperty",
5152+
"properties": [
5153+
{
5154+
"abstract": true,
5155+
"docs": {
5156+
"stability": "experimental"
5157+
},
5158+
"locationInModule": {
5159+
"filename": "lib/compliance.ts",
5160+
"line": 2274
5161+
},
5162+
"name": "property",
5163+
"type": {
5164+
"primitive": "string"
5165+
}
5166+
}
5167+
]
5168+
},
51215169
"jsii-calc.IPrivatelyImplemented": {
51225170
"assembly": "jsii-calc",
51235171
"docs": {
@@ -7360,6 +7408,37 @@
73607408
],
73617409
"name": "ObjectRefsInCollections"
73627410
},
7411+
"jsii-calc.ObjectWithPropertyProvider": {
7412+
"assembly": "jsii-calc",
7413+
"docs": {
7414+
"stability": "experimental"
7415+
},
7416+
"fqn": "jsii-calc.ObjectWithPropertyProvider",
7417+
"kind": "class",
7418+
"locationInModule": {
7419+
"filename": "lib/compliance.ts",
7420+
"line": 2277
7421+
},
7422+
"methods": [
7423+
{
7424+
"docs": {
7425+
"stability": "experimental"
7426+
},
7427+
"locationInModule": {
7428+
"filename": "lib/compliance.ts",
7429+
"line": 2278
7430+
},
7431+
"name": "provide",
7432+
"returns": {
7433+
"type": {
7434+
"fqn": "jsii-calc.IObjectWithProperty"
7435+
}
7436+
},
7437+
"static": true
7438+
}
7439+
],
7440+
"name": "ObjectWithPropertyProvider"
7441+
},
73637442
"jsii-calc.Old": {
73647443
"assembly": "jsii-calc",
73657444
"docs": {
@@ -11128,5 +11207,5 @@
1112811207
}
1112911208
},
1113011209
"version": "0.20.5",
11131-
"fingerprint": "g9C1lL8c+vgxBjOWVBFMMPlcwkF3Z81xxTAGfc73x9o="
11210+
"fingerprint": "0rO96JPKRUt2x4hOyoCkj3VQvwUDmrvfFTBOkOvT86M="
1113211211
}

packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ public void VariadicCallbacksAreHandledCorrectly()
10341034
}
10351035

10361036
[Fact(DisplayName = Prefix + nameof(ReturnSubclassThatImplementsInterface976))]
1037-
public void ReturnSubclassThatImplementsInterface976()
1037+
public void ReturnSubclassThatImplementsInterface976()
10381038
{
10391039
var obj = SomeTypeJsii976.ReturnReturn();
10401040
Assert.Equal(obj.Foo, 333);
@@ -1265,5 +1265,13 @@ public void StructsCanBeDowncastedToParentType()
12651265
Assert.NotNull(Demonstrate982.TakeThis());
12661266
Assert.NotNull(Demonstrate982.TakeThisToo());
12671267
}
1268+
1269+
[Fact(DisplayName = Prefix + nameof(CanUseInterfaceSetters))]
1270+
public void CanUseInterfaceSetters()
1271+
{
1272+
var obj = ObjectWithPropertyProvider.Provide();
1273+
obj.Property = "New Value";
1274+
Assert.True(obj.WasSet());
1275+
}
12681276
}
12691277
}

packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,4 +1553,11 @@ public java.lang.Number next() {
15531553
return next;
15541554
}
15551555
}
1556+
1557+
@Test
1558+
public void canUseInterfaceSetters() {
1559+
final IObjectWithProperty obj = ObjectWithPropertyProvider.provide();
1560+
obj.setProperty("New Value");
1561+
assertTrue(obj.wasSet());
1562+
}
15561563
}

packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5118,6 +5118,54 @@
51185118
}
51195119
]
51205120
},
5121+
"jsii-calc.IObjectWithProperty": {
5122+
"assembly": "jsii-calc",
5123+
"docs": {
5124+
"stability": "experimental",
5125+
"summary": "Make sure that setters are properly called on objects with interfaces."
5126+
},
5127+
"fqn": "jsii-calc.IObjectWithProperty",
5128+
"kind": "interface",
5129+
"locationInModule": {
5130+
"filename": "lib/compliance.ts",
5131+
"line": 2273
5132+
},
5133+
"methods": [
5134+
{
5135+
"abstract": true,
5136+
"docs": {
5137+
"stability": "experimental"
5138+
},
5139+
"locationInModule": {
5140+
"filename": "lib/compliance.ts",
5141+
"line": 2275
5142+
},
5143+
"name": "wasSet",
5144+
"returns": {
5145+
"type": {
5146+
"primitive": "boolean"
5147+
}
5148+
}
5149+
}
5150+
],
5151+
"name": "IObjectWithProperty",
5152+
"properties": [
5153+
{
5154+
"abstract": true,
5155+
"docs": {
5156+
"stability": "experimental"
5157+
},
5158+
"locationInModule": {
5159+
"filename": "lib/compliance.ts",
5160+
"line": 2274
5161+
},
5162+
"name": "property",
5163+
"type": {
5164+
"primitive": "string"
5165+
}
5166+
}
5167+
]
5168+
},
51215169
"jsii-calc.IPrivatelyImplemented": {
51225170
"assembly": "jsii-calc",
51235171
"docs": {
@@ -7360,6 +7408,37 @@
73607408
],
73617409
"name": "ObjectRefsInCollections"
73627410
},
7411+
"jsii-calc.ObjectWithPropertyProvider": {
7412+
"assembly": "jsii-calc",
7413+
"docs": {
7414+
"stability": "experimental"
7415+
},
7416+
"fqn": "jsii-calc.ObjectWithPropertyProvider",
7417+
"kind": "class",
7418+
"locationInModule": {
7419+
"filename": "lib/compliance.ts",
7420+
"line": 2277
7421+
},
7422+
"methods": [
7423+
{
7424+
"docs": {
7425+
"stability": "experimental"
7426+
},
7427+
"locationInModule": {
7428+
"filename": "lib/compliance.ts",
7429+
"line": 2278
7430+
},
7431+
"name": "provide",
7432+
"returns": {
7433+
"type": {
7434+
"fqn": "jsii-calc.IObjectWithProperty"
7435+
}
7436+
},
7437+
"static": true
7438+
}
7439+
],
7440+
"name": "ObjectWithPropertyProvider"
7441+
},
73637442
"jsii-calc.Old": {
73647443
"assembly": "jsii-calc",
73657444
"docs": {
@@ -11128,5 +11207,5 @@
1112811207
}
1112911208
},
1113011209
"version": "0.20.5",
11131-
"fingerprint": "g9C1lL8c+vgxBjOWVBFMMPlcwkF3Z81xxTAGfc73x9o="
11210+
"fingerprint": "0rO96JPKRUt2x4hOyoCkj3VQvwUDmrvfFTBOkOvT86M="
1113211211
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
/// <summary>Make sure that setters are properly called on objects with interfaces.</summary>
6+
/// <remarks>
7+
/// stability: Experimental
8+
/// </remarks>
9+
[JsiiInterface(nativeType: typeof(IObjectWithProperty), fullyQualifiedName: "jsii-calc.IObjectWithProperty")]
10+
public interface IObjectWithProperty
11+
{
12+
/// <remarks>
13+
/// stability: Experimental
14+
/// </remarks>
15+
[JsiiProperty(name: "property", typeJson: "{\"primitive\":\"string\"}")]
16+
string Property
17+
{
18+
get;
19+
set;
20+
}
21+
/// <remarks>
22+
/// stability: Experimental
23+
/// </remarks>
24+
[JsiiMethod(name: "wasSet", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}")]
25+
bool WasSet();
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
/// <summary>Make sure that setters are properly called on objects with interfaces.</summary>
6+
/// <remarks>
7+
/// stability: Experimental
8+
/// </remarks>
9+
[JsiiTypeProxy(nativeType: typeof(IObjectWithProperty), fullyQualifiedName: "jsii-calc.IObjectWithProperty")]
10+
internal sealed class IObjectWithPropertyProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IObjectWithProperty
11+
{
12+
private IObjectWithPropertyProxy(ByRefValue reference): base(reference)
13+
{
14+
}
15+
16+
/// <remarks>
17+
/// stability: Experimental
18+
/// </remarks>
19+
[JsiiProperty(name: "property", typeJson: "{\"primitive\":\"string\"}")]
20+
public string Property
21+
{
22+
get => GetInstanceProperty<string>();
23+
set => SetInstanceProperty(value);
24+
}
25+
26+
/// <remarks>
27+
/// stability: Experimental
28+
/// </remarks>
29+
[JsiiMethod(name: "wasSet", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}")]
30+
public bool WasSet()
31+
{
32+
return InvokeInstanceMethod<bool>(new System.Type[]{}, new object[]{});
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
/// <remarks>
6+
/// stability: Experimental
7+
/// </remarks>
8+
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.ObjectWithPropertyProvider), fullyQualifiedName: "jsii-calc.ObjectWithPropertyProvider")]
9+
public class ObjectWithPropertyProvider : DeputyBase
10+
{
11+
protected ObjectWithPropertyProvider(ByRefValue reference): base(reference)
12+
{
13+
}
14+
15+
protected ObjectWithPropertyProvider(DeputyProps props): base(props)
16+
{
17+
}
18+
19+
/// <remarks>
20+
/// stability: Experimental
21+
/// </remarks>
22+
[JsiiMethod(name: "provide", returnsJson: "{\"type\":{\"fqn\":\"jsii-calc.IObjectWithProperty\"}}")]
23+
public static Amazon.JSII.Tests.CalculatorNamespace.IObjectWithProperty Provide()
24+
{
25+
return InvokeStaticMethod<Amazon.JSII.Tests.CalculatorNamespace.IObjectWithProperty>(typeof(Amazon.JSII.Tests.CalculatorNamespace.ObjectWithPropertyProvider), new System.Type[]{}, new object[]{});
26+
}
27+
}
28+
}

packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
9999
case "jsii-calc.IJsii496": return software.amazon.jsii.tests.calculator.IJsii496.class;
100100
case "jsii-calc.IMutableObjectLiteral": return software.amazon.jsii.tests.calculator.IMutableObjectLiteral.class;
101101
case "jsii-calc.INonInternalInterface": return software.amazon.jsii.tests.calculator.INonInternalInterface.class;
102+
case "jsii-calc.IObjectWithProperty": return software.amazon.jsii.tests.calculator.IObjectWithProperty.class;
102103
case "jsii-calc.IPrivatelyImplemented": return software.amazon.jsii.tests.calculator.IPrivatelyImplemented.class;
103104
case "jsii-calc.IPublicInterface": return software.amazon.jsii.tests.calculator.IPublicInterface.class;
104105
case "jsii-calc.IPublicInterface2": return software.amazon.jsii.tests.calculator.IPublicInterface2.class;
@@ -135,6 +136,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
135136
case "jsii-calc.NullShouldBeTreatedAsUndefinedData": return software.amazon.jsii.tests.calculator.NullShouldBeTreatedAsUndefinedData.class;
136137
case "jsii-calc.NumberGenerator": return software.amazon.jsii.tests.calculator.NumberGenerator.class;
137138
case "jsii-calc.ObjectRefsInCollections": return software.amazon.jsii.tests.calculator.ObjectRefsInCollections.class;
139+
case "jsii-calc.ObjectWithPropertyProvider": return software.amazon.jsii.tests.calculator.ObjectWithPropertyProvider.class;
138140
case "jsii-calc.Old": return software.amazon.jsii.tests.calculator.Old.class;
139141
case "jsii-calc.OptionalArgumentInvoker": return software.amazon.jsii.tests.calculator.OptionalArgumentInvoker.class;
140142
case "jsii-calc.OptionalConstructorArgument": return software.amazon.jsii.tests.calculator.OptionalConstructorArgument.class;

0 commit comments

Comments
 (0)