fix(st2client): fix TypeError when displaying help for actions with mixed parameter position types#6375
fix(st2client): fix TypeError when displaying help for actions with mixed parameter position types#6375balgaly wants to merge 3 commits intoStackStorm:masterfrom
Conversation
…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
…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.
|
|
|
I pushed a follow-up commit adding unit tests for On the CI failures: the |
- Remove extra spaces after ':' in test dict literals (flake8 E241) - Add CHANGELOG.rst entry under 'in development' for StackStorm#6375
|
Just pushed a follow-up to fix the remaining CI failures:
All CI checks should pass now. Happy to make any other changes. |
Summary
Fixes #5130 —
st2 run pack.action -hcrashes withTypeError: '<' not supported between instances of 'str' and 'int'when the action has some parameters with a numericpositionattribute and others without.Root cause
_get_parameter_sort_valuereturns eitherint(position)orstr(name)depending on whether the parameter has apositionattribute. Python 3 does not support<comparisons betweenintandstr, sosorted()raises aTypeErrorwhen it tries to compare parameters of both kinds.Fix
Replace the flat return value with a 3-tuple
(tier, int_pos, name):positionattribute return(0, int(position), "")-- sorted by position first.positionattribute 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 (
0vs1), Python never attempts to compare anintagainst astr.Test
Reproducer (from the issue):
The fix is additive -- any action whose parameters all have
positionattributes or all lack them continues to sort identically.