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

Typeerror within states/helpers.py on init #28

Open
RobertTownley opened this issue May 19, 2020 · 1 comment
Open

Typeerror within states/helpers.py on init #28

RobertTownley opened this issue May 19, 2020 · 1 comment

Comments

@RobertTownley
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants