-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Incorrect assignment of session variables in loop #4101
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
Conversation
|
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 |
| self.workflow_manage.parentWorkflowManage.chat_context) | ||
| else: | ||
| self.workflow_manage.get_chat_info().set_chat_variable(self.workflow_manage.chat_context) | ||
| return NodeResult({'variable_list': variable_list, 'result_list': result_list}, {}) |
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 code appears to modify the chat context of a workflow based on whether workflow_manage is an instance of LoopWorkflowManage. There might be improvements and potential checks:
-
Type Checking: The type check for
if isinstance(self.workflow_manager, LoopWorkflowManage)could benefit from including additional types (e.g., subclassing) or adding more specific conditions. -
Default Case Handling: If
self.workflow_manageis not an instance of eitherLoopWorkflowManageror another expected class, it doesn't explicitly handle this scenario. Consider logging a warning/error message with some kind of default behavior. -
Potential Null or Undefined Behavior: Ensure that
chat_contextis defined and accessible before attempting to set it. This can lead to undefined errors if access happens after object initialization and de-allocation.
Here's the revised version with these suggestions:
def execute(self, variable_list, stream, **kwargs) -> NodeResult:
from application.flow.loop_workflow_manage import LoopWorkflowManage
# Check if workflow_manage is a subclass of LoopWorkflowManage
loop_manage_type_check = isinstance(self.workflow_manage, (LoopWorkflowManage,))
parent_manage_type_check = False
# Further checking if self.workflow_manage is an instance of its superclass(es)
if isinstance(self.workflow_manage, (
LoopWorkflowManage,
MyOtherExpectedClass,
)
):
parent_manage_type_check = True
if (loop_manage_type_check or parent_manage_type_check):
assert hasattr(self.workflow_manage, 'parentWorkflowManage'), \
"Missing parentWorkflowManage attribute."
if hasattr(self.workflow_manage.parentWorkflowManage, 'get_chat_info'):
workflow_manager_chat_info = self.workflow_manage.parentWorkflowManage.get_chat_info()
if hasattr(workflow_manager_chat_info, 'set_chat_variable'):
try:
workflow_manager_chat_info.set_chat_variable(
self.workflow_manage.chat_context
)
except Exception as e:
print(f"Error setting chat context: {str(e)}")
else:
print("No valid 'set_chat_variable' method in workflow manager chat info.")
else:
print("No valid 'get_chat_info' method implemented.")
elif hasattr(self.workflow_manager, 'get_chat_info'):
workflow_manager_chat_info = self.workflow_manager.get_chat_info()
if hasattr(workflow_manager_chat_info, 'set_chat_variable'):
workflow_manager_chat_info.set_chat_variable(self.workflow_manage.chat_context)
else:
print("No valid 'set_chat_variable' method in workflow manager chat info.")
else:
print("Incomplete or missing configuration.")
return NodeResult({'variable_list': variable_list, 'result_list': result_list}, {})In summary, we added type checking, included fallback handling, ensured proper existence of attributes, and logged exceptions/errors where applicable. This should help prevent runtime bugs and provide better error reporting during execution.
feat: Incorrect assignment of session variables in loop