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

Fix state management recursive function #128

Open
jsoconno opened this issue Aug 15, 2021 · 0 comments
Open

Fix state management recursive function #128

jsoconno opened this issue Aug 15, 2021 · 0 comments
Labels
bug Something isn't working investigate

Comments

@jsoconno
Copy link
Owner

jsoconno commented Aug 15, 2021

Describe the bug
The recursive function that manages state looks like it might be off.

To Reproduce
There is no issue to reproduce per se. It just seems like the function should be something like:

def search_state(search_dict: dict, search_key: Cluster, output: list = None) -> list:
    """
    Search nested dicts and lists for the search_value (key)
    and return the corresponding value.
    """
    if output is None:
        output = []
    
    for k, v in search_dict.items():
        if k is not search_key and isinstance(v, list):
            for item in v:
                if isinstance(item, dict):
                    search_state(item, search_key, output)
        if isinstance(v, dict): # << add this if block
            search(v, search_key, output)
        else:
            for item in v:
                output.append(item)

    return output

Instead of:

def search_state(search_dict: dict, search_key: Cluster, output: list = None) -> list:
    """
    Search nested dicts and lists for the search_value (key)
    and return the corresponding value.
    """
    if output is None:
        output = []
    
    for k, v in search_dict.items():
        if k is not search_key and isinstance(v, list):
            for item in v:
                if isinstance(item, dict):
                    search_state(item, search_key, output)
        else:
            for item in v:
                output.append(item)

    return output

Expected behavior
State can be searched by architectures code base

Screenshots
None.

Desktop (please complete the following information):
All

Additional context
This has not been tested directly and as mentioned does not appear to be resulting in an issue, but a recent test of this function in a difference context revealed an issue that i think might be present here.

@jsoconno jsoconno added the bug Something isn't working label Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigate
Projects
None yet
Development

No branches or pull requests

1 participant