aws / aws/aws-cdk

aws-stepfunctions: State.jsonpath() silently converts to JSONata when state machine query language is set to JSONata

Open
#35,464 5 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-stepfunctions bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

Currently, creating any state via the JsonPath factory method, for example, `sfn.Pass.jsonpath(stack, 'id')` does not throw an error when it is used in a state machine with `QueryLanguage.JSONATA` set at the top level. This is because the state is actually being interpreted as JSONata.

This results in unintuitive situations where you think you are setting JsonPath properties but are actually creating a JSONata state. This results in time wasted waiting for the cloudformation deployment to fail or for the state machine execution to fail. CDK should throw an error if you are using the `jsonpath()` factory method on a 'JSONata' state machine.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Library Version

_No response_

### Expected Behavior

Creating a state via `state.jsonpath()` should throw an error if it is attached to a state machine with `JSONata` set at the top level.

### Current Behavior

The state created via `state.jsonpath` will silently turn into a `JSONata` state instead.

### Reproduction Steps

```ts
const stack = new cdk.Stack();
const map = sfn.DistributedMap.jsonPath(stack, 'Map', {
// queryLanguage: sfn.QueryLanguage.JSON_PATH, // Setting this throws an error as is expected
maxConcurrency: 1,
itemsPath: sfn.JsonPath.stringAt('$.inputForMap'),
itemSelector: {
foo: 'foo',
bar: sfn.JsonPath.stringAt('$.bar'),
},
});
map.itemProcessor(new sfn.Pass(stack, 'State'));

// Should error but it doesn't! Silently turns our JsonPath distributed map above into a JSONata one!
new sfn.StateMachine(stack, 'StateMachine', {
queryLanguage: sfn.QueryLanguage.JSONATA,
definitionBody: sfn.DefinitionBody.fromChainable(map),
);
```

### Possible Solution

Set `queryLanguage: sfn.QueryLanguage.JSON_PATH` instead of leaving it blank: https://github.com/aws/aws-cdk/blob/cecbabfc1944ce301d89f38dddd5f2f190c7e2d9/packages/aws-cdk-lib/aws-stepfunctions/lib/states/distributed-map.ts#L152

This goes for every other state with this factory method

This would unfortunately need to go behind a feature flag, since throwing an error when there might not have been one before is a breaking change.

Note that the logic for throwing the error already exists here:
https://github.com/aws/aws-cdk/blob/cecbabfc1944ce301d89f38dddd5f2f190c7e2d9/packages/aws-cdk-lib/aws-stepfunctions/lib/states/state.ts#L588

### Additional Information/Context

_No response_

### AWS CDK Library version (aws-cdk-lib)

2.214

### AWS CDK CLI version

2.1029.0

### Node.js Version

24

### OS

MacOS

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with packages/aws-cdk-lib/aws-stepfunctions/lib/states/distributed-map.ts around the queryLanguage default and packages/aws-cdk-lib/aws-stepfunctions/lib/states/state.ts around the existing error logic. Trace how jsonpath() states inherit the top-level query language and review the feature-flag implications. Done means JsonPath factory-created states reject a JSONata state machine without breaking supported existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.