Skip to content
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

aws_stepfunctions: breaking change in 2.178 -> RuntimeError: ModifiedEcsRunTask.to_state_json() takes 1 positional argument but 2 were given #33319

Closed
1 task done
nielsspaap opened this issue Feb 6, 2025 · 3 comments
Assignees
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. p2

Comments

@nielsspaap
Copy link

nielsspaap commented Feb 6, 2025

Describe the bug

Since the release of version 2.178 there is an issue with the EcsRunTask. This is the current class we have:

from copy import copy

from aws_cdk import aws_stepfunctions_tasks as sfn_tasks


class ModifiedEcsRunTask(sfn_tasks.EcsRunTask):
    """Modified ECS task for SFN to incorporate tag propagation.
    """

    def to_state_json(self):
        orig = super().to_state_json()
        ret = copy(orig)
        ret["Parameters"]["PropagateTags"] = "TASK_DEFINITION"
        return ret

This was working fine till 2.177 but now is failing with the following error:

jsii.errors.JavaScriptError: 
  @jsii/kernel.RuntimeError: ModifiedEcsRunTask.to_state_json() takes 1 positional argument but 2 were given
      at KernelHost.completeCallback (/tmp/tmp4sklps6b/lib/program.js:10701:35)
      at KernelHost.callbackHandler (/tmp/tmp4sklps6b/lib/program.js:10689:41)
      at EcsRunTask.value (/tmp/tmp4sklps6b/lib/program.js:9294:45)
      at StateGraph.toGraphJson (/tmp/jsii-kernel-rKDUzb/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-graph.js:1:2397)
      at ChainDefinitionBody.bind (/tmp/jsii-kernel-rKDUzb/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-machine.js:1:14236)
      at new StateMachine (/tmp/jsii-kernel-rKDUzb/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-machine.js:1:8347)
      at Kernel._Kernel_create (/tmp/tmp4sklps6b/lib/program.js:9128:25)
      at Kernel.create (/tmp/tmp4sklps6b/lib/program.js:8798:93)
      at KernelHost.processRequest (/tmp/tmp4sklps6b/lib/program.js:10718:36)
      at KernelHost.run (/tmp/tmp4sklps6b/lib/program.js:10678:22)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/__w/13/s/dp_venv/lib/python3.12/site-packages/anl_cicd/flows/deploy/publication_pipeline/deploy.py", line 86, in deploy
    stack = PublicationStack(
            ^^^^^^^^^^^^^^^^^
  File "/__w/13/s/dp_venv/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/__w/13/s/dp_venv/lib/python3.12/site-packages/anl_cicd/flows/deploy/publication_pipeline/stack.py", line 26, in __init__
    workflow = setup_workflow(
               ^^^^^^^^^^^^^^^
  File "/__w/13/s/dp_venv/lib/python3.12/site-packages/anl_workflow/specification/setup_workflow.py", line 28, in setup_workflow
    workflow = Workflow(
               ^^^^^^^^^
  File "/__w/13/s/dp_venv/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/__w/13/s/dp_venv/lib/python3.12/site-packages/anl_workflow/specification/construct.py", line 192, in __init__
    self.state_machine = sfn.StateMachine(
                         ^^^^^^^^^^^^^^^^^
  File "/__w/13/s/dp_venv/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

2.177

Expected Behavior

1 positional argument is needed

Current Behavior

2 positional argument are needed

Reproduction Steps

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.178

Framework Version

No response

Node.js Version

OS

Any

Language

Python

Language Version

No response

Other information

No response

@nielsspaap nielsspaap added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 6, 2025
@github-actions github-actions bot added @aws-cdk/aws-stepfunctions Related to AWS StepFunctions potential-regression Marking this issue as a potential regression to be checked by team member labels Feb 6, 2025
@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p1 and removed needs-triage This issue or PR still needs to be triaged. labels Feb 6, 2025
@paulhcsun
Copy link
Contributor

paulhcsun commented Feb 6, 2025

Hi @nielsspaap, thank you for reporting this issue. This is be the related change: #32343

This seems to be because of a change in the toStateJson() method signature which accepts new optional parameter topLevelQueryLanguage which you have overridden in the ModifiedEcsRunTask class:

public toStateJson(topLevelQueryLanguage?: QueryLanguage): object {

StateMachineProps has a new optional parameter called queryLanguage that gets passed to the toStateJson() method via the toGraphJson() method in the ChainDefinitionBody.bind() call.

  public bind(scope: Construct, _sfnPrincipal: iam.IPrincipal, sfnProps: StateMachineProps, graph?: StateGraph): DefinitionConfig {
    const graphJson = graph!.toGraphJson(sfnProps.queryLanguage);
    return {
      definitionString: Stack.of(scope).toJsonString({
        ...graphJson,
        Comment: sfnProps.comment,
        QueryLanguage: sfnProps.queryLanguage,
      }),
    };
  }

The extra parameter is always passed in the bind() method and this is what is causing your code to break since your implementation overrides the toStateJson() method.

We are currently looking for a solution on our end as this is not a trivial fix since some customers may already be relying on the new implementation in v2.178.0 and reverting this change can also be a breaking change for them. We appreciate your patience.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 6, 2025
@samson-keung
Copy link
Contributor

samson-keung commented Feb 6, 2025

Hi @nielsspaap,

Since you’re using Python CDK, which relies on JSII to bridge CDK Javascript and Python communication, there are some limitations when overriding methods. The error you’re encountering is due to one of these limitations.
To resolve this, you’ll need to modify your method signature to accept additional arguments. Specifically, update the def to_state_json(self) to def to_state_json(self, **kwargs) . This change is necessary due to how JSII handles method overriding between JavaScript and Python and should solve the issue you are encountering. You can find more details about these limitations in the CDK documentation, particularly in the “Arguments and properties” section.

@samson-keung samson-keung self-assigned this Feb 6, 2025
@samson-keung samson-keung added p2 and removed p1 potential-regression Marking this issue as a potential regression to be checked by team member labels Feb 7, 2025
Copy link

github-actions bot commented Feb 7, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. p2
Projects
None yet
Development

No branches or pull requests

4 participants