-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: When the function parameter is of non string type, if the parameter is empty, the function will run with an error #3053 #3107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ def valid_reference_value(_type, value, name): | |
|
||
|
||
def convert_value(name: str, value, _type, is_required, source, node): | ||
if not is_required and value is None: | ||
if not is_required and (value is None or (isinstance(value, str) and len(value) == 0)): | ||
return None | ||
if source == 'reference': | ||
value = node.workflow_manage.get_reference_field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided function Issue: The current check Suggestion: Here's the updated code snippet: @@ -49,7 +49,6 @@ def valid_reference_value(_type, value, name):
def convert_value(name: str, value, _type, is_required, source, node):
if not is_required and value is None:
return None
# Check if source is reference
if source == 'reference':
# Get value using workflow_manage.get_reference_field method This ensures that the conversion logic only executes if the value is not |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code has a few concerns:
Redundant Check: The second
if
statement checks both ifsource
is'reference'
and if the value is empty. This redundancy can be resolved by checking only one condition.String Length Consideration: The current implementation does not explicitly handle cases where the input could contain non-string values that should also be considered "empty," although it implicitly handles them because
None
is handled separately.Immutability of List: Although this doesn't appear to cause an issue with the given code, lists cannot be used immutably in certain contexts without explicit conversion (e.g., using tuple assignment).
Here's a revised version with these considerations addressed:
Key Changes:
if
._type
is'title-cased'
and there is no content.ValueError
for required fields that areNone
.These changes help improve readability, error handling, and potentially performance depending on context.