Comment 2 for bug 1371160

Revision history for this message
Sean Dague (sdague) wrote :

On the Nova side eliminating the stack trace seems like:

def find_path_in_tree(data, path_tokens):
    # given a dict/list tree, and a path in that tree, return data found there.
    for i in range(0, len(path_tokens)):
        if isinstance(data, dict) or isinstance(data, list):
            if path_tokens[i] in data:
                data = data[path_tokens[i]]
            else:
                raise KeyError("/".join(path_tokens[0:i]))
        else:
            if i != len(path_tokens) - 1:
                raise KeyError("/".join(path_tokens[0:i]))
            data = data[path_tokens[i]]
    return data

Because we are in a for loop we have the possibility of assigning data to be the value of a lookup, which turns out to be a string, and then iterating again, it's not a dict, then trying to use the token to index a string... which is wrong.

I'm not actually sure what the right behavior is here. It sort of feels like an early return might be right, but I'm definitely not convinced I understand the implications there.