ssm-diff
ssm-diff copied to clipboard
Typeerror within states/helpers.py on init
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