fix(st2client): fix TypeError when displaying help for actions with mixed parameter position types#6375
Open
balgaly wants to merge 1 commit intoStackStorm:masterfrom
Open
fix(st2client): fix TypeError when displaying help for actions with mixed parameter position types#6375balgaly wants to merge 1 commit intoStackStorm:masterfrom
balgaly wants to merge 1 commit 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.