'Unwanted automatic type conversion

The following code

"""
Gets the error cause from a pipeline execution status.

:param execution_status: is the pipeline execution status.
:type execution_status: dictionary.
:returns: the pipeline execution error cause and the name of the step.
:rtype: dictionary.
"""
def get_error_cause(execution_status):
  error_cause = "Unknown"
  error_step = "Unknown"
  steps = execution_status['Steps']
  if steps:
    for step in steps:
      if 'FailureReason' in step:
        print(str(type(step['Name'])))
        error_step = step['Name'],
        print(str(type(error_step)))
        error_cause = step['FailureReason']
        break
  else:
    error_cause = execution_status['FailureReason']
  return {
    'Step': error_step,
    'Cause': error_cause
  }

when executed in AWS Lambda environment, is automatically converting a str into a tuple. The outputs for the two "print" methods that appear in the code are the following:

<class 'str'>

<class 'tuple'>

This is causing that when serializing the dictionary returned by the method as a JSON, instead of serializing the value of the 'Step' key as a string, it is serialized as a list:

{
  "Step": ["ConcatenateColumns"],
  "Cause": "AccessDenied"
}

The input of the method is a JSON deserialized into a dictionary, like this:

{
    "ExecutionID": "some_execution_ID",
    "Status": "Failed",
    "ElapsedMinutes": 13.0,
    "Steps": [{
        "Name": "ConcatenateColumns",
        "Status": "Failed",
        "ElapsedMinutes": 13.0,
        "FailureReason": "AccessDenied"
    }],
    "FailureReason": "Step failure: One or multiple steps failed."
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source