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 the call api cannot handle empty results #1789

Merged
merged 3 commits into from
Nov 15, 2022

Conversation

caberos
Copy link
Contributor

@caberos caberos commented Nov 9, 2022

Copy link
Member

@allmightyspiff allmightyspiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only resolve the issue when the API results are exactly [[], [], []] which isn't great.

What you should do, is add a check to https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/CLI/formatting.py#L410.

something like

def _format_list(result):
    """Format list responses into a table."""
    
    if not result:
        return result
    table = Table(['value'])
    new_result = [item for item in result if item]
    if len(new_result) == 0: 
        table.add_row(["-"])
        return table
    if isinstance(new_result[0], dict):
        return _format_list_objects(new_result)

   
    for item in new_result:
        table.add_row([iter_to_table(item)])
    return table

And adding a unit test for this specific situation would be good too.

Thanks

@allmightyspiff
Copy link
Member

image

Looks good, thanks

@allmightyspiff allmightyspiff linked an issue Nov 15, 2022 that may be closed by this pull request
@allmightyspiff allmightyspiff merged commit d287bc0 into softlayer:master Nov 15, 2022
@allmightyspiff allmightyspiff mentioned this pull request Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Call API can't handle empty results sometimes
2 participants