st2
st2 copied to clipboard
Issue with action help display when having ordered optional parameters
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 https://github.com/StackStorm/st2/blob/5c4e5f8e93c7ed83c4aa4d196085c2912ae7b285/st2client/st2client/commands/action.py#L779
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.