Skip to content

fix(st2client): fix TypeError when displaying help for actions with mixed parameter position types#6375

Open
balgaly wants to merge 1 commit intoStackStorm:masterfrom
balgaly:fix/action-help-sort-5130
Open

fix(st2client): fix TypeError when displaying help for actions with mixed parameter position types#6375
balgaly wants to merge 1 commit intoStackStorm:masterfrom
balgaly:fix/action-help-sort-5130

Conversation

@balgaly
Copy link
Copy Markdown

@balgaly balgaly commented Apr 8, 2026

Summary

Fixes #5130st2 run pack.action -h crashes with TypeError: '<' not supported between instances of 'str' and 'int' when the action has some parameters with a numeric position attribute and others without.

Root cause

_get_parameter_sort_value returns either int(position) or str(name) depending on whether the parameter has a position attribute. Python 3 does not support < comparisons between int and str, so sorted() raises a TypeError when it tries to compare parameters of both kinds.

Fix

Replace the flat return value with a 3-tuple (tier, int_pos, name):

  • Parameters with a position attribute return (0, int(position), "") -- sorted by position first.
  • Parameters without a position attribute return (1, 0, name) -- sorted alphabetically after positioned ones.

Tuples are compared element-by-element. Because the first element always differs between the two groups (0 vs 1), Python never attempts to compare an int against a str.

Test

Reproducer (from the issue):

st2 run librenms.get_bgp_sessions -h
# was: ERROR: Unable to print help for action "librenms.get_bgp_sessions". '<' not supported between instances of 'str' and 'int'
# now: displays help correctly

The fix is additive -- any action whose parameters all have position attributes or all lack them continues to sort identically.

…ed position types

Parameters with a numeric 'position' attribute and those without (falling
back to name) cannot be compared with '<' in Python 3, causing an unhelpful
TypeError when running 'st2 run action -h' on actions with ordered params.

Replace the flat sort key with a 3-tuple (tier, position, name) so that
positioned params sort before unpositioned ones and no cross-type comparison
is ever attempted.

Fixes StackStorm#5130
@pull-request-size pull-request-size bot added the size/S PR that changes 10-29 lines. Very easy to review. label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S PR that changes 10-29 lines. Very easy to review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with action help display when having ordered optional parameters

1 participant