Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(stepfunctions): read a JSONata variable with the value null as null, not undefined (#2423)
mishukdutta-czb36a75c825f6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 58a8c725..02615a75 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]### Fixed+- **Step Functions — JSONata variables with the value `null`** — a variable assigned `null` read back as undefined, so `{% $var %}` failed with `States.QueryEvaluationError`; it now reads back as `null`, as on AWS. An unset variable still fails.- **Lambda — Kinesis event source mapping filters** — a `FilterCriteria` pattern on a Kinesis record's `data` or on its metadata (`partitionKey`, `sequenceNumber`, ...) never matched, so a mapping with filters dropped every record. Patterns are now matched as AWS documents them: metadata fields next to the event fields, and `data` decoded from base64 as JSON. Data that isn't JSON can't match a `data` pattern but still matches metadata patterns.- **Lambda — two MiniStacks on one host no longer remove each other's function code** — the provided-runtime and Docker-executor extraction caches lived at fixed paths in the shared temp directory, so a second instance on the same host deleted a tree the first was still running from ("leftover from a previous process") and its `reset()` removed the first one's caches; an invocation then failed with `No such file or directory: .../bootstrap`. Both caches are now named for the instance's `GATEWAY_PORT`. Contributed by @skialpine.### Addeddiff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.pyindex 0edd500f..23d86e36 100644--- a/ministack/services/stepfunctions.py+++ b/ministack/services/stepfunctions.py@@ -3072,13 +3072,17 @@ def _evaluate_jsonata(expression, raw_input, ctx=None, result=None, error_output# is the reserved variable. The document is left unset (None) so bare paths# do not resolve against the state input, which AWS reaches only via# `$states.input`.- bindings = dict(ctx.get("variables", {}))- bindings["states"] = statesif jsonata is None:raise _ExecutionError("States.QueryEvaluationError","JSONata support requires the jsonata-python package, which is ""not installed in this build")+ # jsonata-python reads a None binding as undefined, so a null variable uses its NULL_VALUE sentinel.+ bindings = {+ name: jsonata.utils.Utils.NULL_VALUE if value is None else value+ for name, value in ctx.get("variables", {}).items()+ }+ bindings["states"] = statestry:expr = jsonata.Jsonata.jsonata(expression, timeout=1000)_register_sfn_jsonata_functions(expr)diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.pyindex 93b5eda2..45db5863 100644--- a/tests/test_stepfunctions.py+++ b/tests/test_stepfunctions.py@@ -8000,6 +8000,39 @@ def test_sfn_jsonata_undefined_variable_raises_query_eval_error(sfn_sync):sfn_sync.delete_state_machine(stateMachineArn=sm_arn)+def test_sfn_jsonata_assign_null_variable_reads_back_as_null(sfn_sync):+ """A variable with the value `null` reads back as `null`, not as undefined.+ AWS keeps the two apart: only an unset variable fails."""+ import uuid as _uuid_local+ sm_name = f"jsonata-assign-null-{_uuid_local.uuid4().hex[:8]}"+ sm_arn = sfn_sync.create_state_machine(+ name=sm_name,+ roleArn="arn:aws:iam::000000000000:role/test-role",+ definition=json.dumps({+ "QueryLanguage": "JSONata",+ "StartAt": "SetNull",+ "States": {+ "SetNull": {+ "Type": "Pass",+ "Assign": {"v": None},+ "Next": "ReadNull",+ },+ "ReadNull": {+ "Type": "Pass",+ "Output": {"v": "{% $v %}"},+ "End": True,+ },+ },+ }),+ )["stateMachineArn"]+ try:+ resp = sfn_sync.start_sync_execution(stateMachineArn=sm_arn, input="{}")+ assert resp["status"] == "SUCCEEDED"+ assert json.loads(resp["output"]) == {"v": None}+ finally:+ sfn_sync.delete_state_machine(stateMachineArn=sm_arn)++def test_sfn_jsonata_assign_reuses_input(sfn_sync):"""`Assign` can reference `$states.input` (always available)."""import uuid as _uuid_local