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

Issue with action help display when having ordered optional parameters #5130

Open
kedare opened this issue Jan 28, 2021 · 2 comments · May be fixed by #6266
Open

Issue with action help display when having ordered optional parameters #5130

kedare opened this issue Jan 28, 2021 · 2 comments · May be fixed by #6266

Comments

@kedare
Copy link

kedare commented Jan 28, 2021

SUMMARY

On some cases, when trying to display the help st2 run action pack.action -h on an action that has ordered parameters like this one from the librenms pack

STACKSTORM VERSION

Paste the output of st2 --version:

st2 --version
st2 3.3.0, on Python 3.9.1
OS, environment, install method

Post what OS you are running this on, along with any other relevant information/

  • st2-docker

Steps to reproduce the problem

Install the following pack : https://github.com/kedare/stackstorm-librenms
Try to run the following command :

st2 run librenms.get_bgp_sessions -h
st2 run librenms.get_devices -h

Expected Results

The help to be shown

Actual Results

The following output is displayed

Get BGP sessions

ERROR: Unable to print help for action "librenms.get_bgp_sessions". '<' not supported between instances of 'str' and 'int'

Investigation

The error is catched there

print('ERROR: Unable to print help for action "%s". %s' %

Help by amanda on the Slack channel:

Added some debug after reproducing:

Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/action.py", line 771, in _print_help
    names=optional)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/action.py", line 898, in _sort_parameters
    sorted_parameters = sorted(names, key=lambda name:
TypeError: '<' not supported between instances of 'str' and 'int'

It looks like it's to do with the position parameters, the sort uses name or position depending on which is given.
If I get rid of the position attributes, then the help works.

So looks like a bug that when it does the sort it indices some by position and others by name, and then can't sort. As presumably the parameters from the runner are indexed by name.
Could you raise an issue on ST2 for this? I think it's probalby that in python 2 it would allow this comparison, but on python 3 then we probably need to convert the position to a string in that sort. So it should be a simple fix to ST2 if you want to take a look.

@kedare kedare changed the title Issue with action help generation when having ordered parameter Issue with action help generation when having ordered parameters Jan 28, 2021
@amanda11
Copy link
Contributor

amanda11 commented Jan 28, 2021

Problem reproduced on a 3.4dev system.

A quick hack to resolve this on a local system was to change st2client/commands/action.py to

def _get_parameter_sort_value(self, parameters, name):
        """
        Return a value which determines sort order for a particular parameter.
        By default, parameters are sorted using "position" parameter attribute.
        If this attribute is not available, parameter is sorted based on the
        name.
        """
        parameter = parameters.get(name, None)
        if not parameter:
            return None
        sort_value = str(parameter.get('position', name))
        return sort_value

@kedare kedare changed the title Issue with action help generation when having ordered parameters Issue with action help display when having ordered optional parameters Jan 28, 2021
@shubhamsugara22
Copy link

@amanda11 hi is the issue still there or fixed , can discuss and generate a PR for this

shubhamsugara22 added a commit to shubhamsugara22/st2 that referenced this issue Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants