-
Notifications
You must be signed in to change notification settings - Fork 247
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
Python None
maps to JS/TS undefined
instead of null
#3999
Comments
Jsii APIs cannot distinguish between |
|
If any part of a state's JSON representation is `null`, that value will be replaced by `undefined` when jsii sends data to the other language, resulting in a change of semantics. Multi-language APIs cannot differentiate between `null` and `undefined` as non-JS languages typically fail to distinguish between them... In order to address that, a `JsonNull` value was added which serializes to `null` (via Javascript's standard `toJSON` method), which must be used in such cases where `null` may need to cross the language boundary. The `JsonPath.DISCARD` value is now a string-token representation of the `JsonNull` instance. Fixes #14639 Fixes aws/jsii#3999 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
If any part of a state's JSON representation is `null`, that value will be replaced by `undefined` when jsii sends data to the other language, resulting in a change of semantics. Multi-language APIs cannot differentiate between `null` and `undefined` as non-JS languages typically fail to distinguish between them... In order to address that, a `JsonNull` value was added which serializes to `null` (via Javascript's standard `toJSON` method), which must be used in such cases where `null` may need to cross the language boundary. The `JsonPath.DISCARD` value is now a string-token representation of the `JsonNull` instance. Fixes aws#14639 Fixes aws/jsii#3999 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Describe the bug
It seems that JSII may be interpreting a Python
None
value orNoneType
object asundefined
rather thannull
. I am working with Step Functions state machines in the CDK in Python and when I useresult_path=JsonPath.DISCARD
this gets set to"ResultPath": None
in the resulting state machine definition as a Python dictionary. But then either callingstack.resolve
or just during the resolution process duringcdk synth
theResultPath
property get's removed entirely. I can see here whereresolve
removed properties withundefined
value. https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/core/lib/private/resolve.ts#L222. But when converting from code to JSON,null
is a valid value, which Python'sNone
value usually maps to.Expected Behavior
When creating a Step Function state with
result_path=JsonPath.DISCARD
I expect the resulting state machine definition to include"ResultPath": null
.Current Behavior
Currently, if I create a state with
result_path=JsonPath.DISCARD
the resulting state machine definition does not include theResultPath
field at all.Reproduction Steps
Run
cdk synth
with the stack above. Inspect the 3 files created in the cdk.out directory. The map-state.json and state-graph.json files will show the"ResultPath": null
, but the state-graph-resolved.json file will not include theResultPath
field on theMap
state at all.Possible Solution
I'm not entirely sure of a solution as in some contexts it makes sense for Python
None
values to map toundefined
and other times it makes sense for it to map tonull
. I don't believe Python has a way to distinguish the 2. Perhaps the CDK or JSII need an enum or constant to representnull
in those contexts wherenull
is valid and thenNone
will always be treated asundefined
.Additional Information/Context
I have noticed this on multiple state types now, but both related to a
Map
state. I've found this behavior on both theMap
state itself and when I addresult_path=JsonPath.DISCARD
to a task state within theMap
state iterator. Neither had theResultPath
field in the synthesized/resolved state machine definition.SDK version used
2.68.0 (build 25fda51)
Environment details (OS name and version, etc.)
Mac OS 13.2.1, Python 3.9.6
The text was updated successfully, but these errors were encountered: