Open shubhamsugara22 opened 1 month ago
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.
@nzlosh @cognifloyd can you check getting lint error again and again adjusted the file according to black format still logic is fine but because of lint check is failing
@amanda11 @nzlosh @cognifloyd Can you review this request ?
Converting position to string will change the sort order; for example "10"
sorts before "2"
. So, I'm concerned about merging this solution.
@cognifloyd made some changes but does it look like , is this change feasible to apply if yes , then can discuss how to proceed further otherwise , we can close if the issue doesn't look like solving
The logic is now pretty much the same as before.
I think a clean way to solve this would be to create a custom object wrapper that handles sorting comparisons. The object would wrap either name
or position
(a str
or int
). When the objects are compared with each other, an int
should be sorted before a str
, and if the types are the same, use the standard python comparison.
Something like this (ignore the class it can be updated later & mainly focus on logic) @cognifloyd
class ParameterWrapper:
def __init__(self, value):
self.value = value
def __lt__(self, other):
# Prioritize int values over str values
if isinstance(self.value, int) and isinstance(other.value, str):
return True
if isinstance(self.value, str) and isinstance(other.value, int):
return False
# Use natural ordering if types are the same
return self.value < other.value
def __repr__(self):
return f"ParameterWrapper({self.value})"
and update the existing function
if parameter:
position = parameter.get("position")
# Return a ParameterWrapper object for consistent sorting behavior
return ParameterWrapper(position if position is not None else name)
Summary:
This PR addresses the issue where the
st2 run action pack.action -h
command fails with aTypeError: '<' not supported between instances of 'str' and 'int'
. The error occurs when sorting action parameters that have a mix of names (strings) and positions (integers). In Python 3, comparing these types directly causes a failure.Root Cause:
The sorting function attempts to sort action parameters by either the
position
attribute (if present) or thename
. In some cases,position
is an integer whilename
is a string, leading to a type comparison error in Python 3.Fix:
The
_get_parameter_sort_value
method has been updated to:position
attribute to a string (if it exists) for consistent sorting.name
whenposition
is not available.Fixes #5130