runtheops / ssm-diff

A human-friendly way of managing parameters in AWS SSM
MIT License
46 stars 26 forks source link

Typeerror within states/helpers.py on init #28

Open RobertTownley opened 4 years ago

RobertTownley commented 4 years ago

I pip installed the client to a python 3.8 virtual environment, and ran the initial ssm-diff init command, but encountered a type error:

Traceback (most recent call last):
  File "/Users/roberttownley/.pyenv/versions/demo/bin/ssm-diff", line 82, in <module>
    args.func(args)
  File "/Users/roberttownley/.pyenv/versions/demo/bin/ssm-diff", line 11, in init
    l.save(r.get(flat=False, paths=args.path))
  File "/Users/roberttownley/.pyenv/versions/3.8.2/envs/demo/lib/python3.8/site-packages/states/states.py", line 108, in get
    add(obj=output,
  File "/Users/roberttownley/.pyenv/versions/3.8.2/envs/demo/lib/python3.8/site-packages/states/helpers.py", line 61, in add
    obj[part] = value
TypeError: 'str' object does not support item assignment

I added a print statement to the add funciton within states/helpers.py to see the state of obj, and the forloop iteration just before it fails has converted the object into a string, which causes the next item placement to fail.

In the iteration prior to that, the object contains two keys, with one of them containing a nested object. I added the following debug print statements, and have the last few iterations of output pasted below it:

# Modified add function

def add(obj, path, value):
    parts = path.strip("/").split("/")
    last = len(parts) - 1

    for index, part in enumerate(parts):
        print("Current obj: ", type(obj))
        print(obj)
        if index == last:
            obj[part] = value
        else:
            obj = obj.setdefault(part, {})
# Output
{'Networking': {'VPC': {'Managment': {'AandBblock': 'XXXXX'}, 'Research': 'YYYYY'}}}
Current obj:  <class 'dict'>
{'VPC': {'Managment': {'AandBblock': 'XXXXX}, 'Research': 'YYYYY'}}
Current obj:  <class 'dict'>
{'Managment': {'AandBblock': 'XXXXX'}, 'Research': 'YYYYY'}
Current obj:  <class 'str'>
YYYYY
shankarsundaram commented 3 years ago

I ran into same issue . is there any way to unblock it?