Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

feat: Incorrect assignment of session variables in loop

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 24, 2025

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 24, 2025

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit 04b42c3 into v2 Sep 24, 2025
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_loop branch September 24, 2025 09:21
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}, {})
Copy link
Contributor Author

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:

  1. 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.

  2. Default Case Handling: If self.workflow_manage is not an instance of either LoopWorkflowManager or another expected class, it doesn't explicitly handle this scenario. Consider logging a warning/error message with some kind of default behavior.

  3. Potential Null or Undefined Behavior: Ensure that chat_context is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants