Skip to content

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

Open
balgaly wants to merge 3 commits 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 3 commits 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
…ypes

Regression tests for StackStorm#5130. Covers the case where some parameters have
a numeric 'position' attribute and others do not, which previously caused
sorted() to raise TypeError in Python 3. Also covers all-positioned and
all-unpositioned parameter lists to confirm existing sort behaviour is
preserved.
@pull-request-size pull-request-size bot added size/M PR that changes 30-99 lines. Good size to review. and removed size/S PR that changes 10-29 lines. Very easy to review. labels Apr 9, 2026
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@balgaly
Copy link
Copy Markdown
Author

balgaly commented Apr 9, 2026

I pushed a follow-up commit adding unit tests for _sort_parameters and _get_parameter_sort_value to st2client/tests/unit/test_command_actionrun.py. Three cases are covered: mixed positioned/unpositioned parameters (the regression case from #5130), all parameters with a position, and all parameters without.

On the CI failures: the Integration Tests (Orquesta) - Python 3.10 job failed, but the same test passed for Python 3.8, 3.9, and 3.11. The change here is a client-side sort key with no server-side effect, so it cannot influence Orquesta workflow execution. Cross-referencing against PR #6372, the base branch has had intermittent CI instability for some time. The failure looks pre-existing rather than anything introduced by this PR.

- Remove extra spaces after ':' in test dict literals (flake8 E241)
- Add CHANGELOG.rst entry under 'in development' for StackStorm#6375
@balgaly
Copy link
Copy Markdown
Author

balgaly commented Apr 11, 2026

Just pushed a follow-up to fix the remaining CI failures:

  • Flake8 E241 — removed extra alignment spaces after : in the test dict literals (lines 414/417 of test_command_actionrun.py)
  • CHANGELOG.rst — added an entry under in development as required

All CI checks should pass now. Happy to make any other changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR that changes 30-99 lines. Good size 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

2 participants