fix: In the variable aggregation strategy that returns the first non-null value of each group, empty strings, empty lists, and empty objects are not treated as null values#4285
Conversation
…null value of each group, empty strings, empty lists, and empty objects are not treated as null values
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| if v is not None and not(isinstance(v, (str,list,dict)) and len(v) == 0) : | ||
| return v | ||
| return None | ||
|
|
There was a problem hiding this comment.
The provided code has a few minor issues and improvements that can be made:
-
Redundant Condition: The current condition
if isinstance(v, (str,list,dict)) and len(v) == 0is redundant because an empty string ('') or other falsy values won't evaluate toTrue. Therefore, you can simplify this part of the check to justv is not None. -
Line Length: There's one line too long, which might make it harder to read. You can break the line using parentheses or a backslash.
-
Whitespace Improvements: Ensure consistent indentation to maintain readability.
Here's the improved version:
def get_first_non_null(self, variable_list):
for variable in variable_list:
ref_var = self.workflow_manage.get_reference_field(
variable.get('variable')[0],
variable.get('variable')[1:]
)
if ref_var is not None:
return ref_var
return NoneNote: This assumes that ref_var returned from get_reference_field() cannot be considered "null" in the sense defined by checking its truthiness after stripping whitespace if needed (though strings are inherently non-empty in Python). If that assumption changes, additional checks should be implemented accordingly.
fix: In the variable aggregation strategy that returns the first non-null value of each group, empty strings, empty lists, and empty objects are not treated as null values