[Bugfix] Fix the bug that call flow in flow function will fail #2267
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently call a flow in a flow node will fail due to wrongly handled operation context, in this PR, we fix it by copy the original context and recover.
Issue: #2237
This pull request primarily focuses on refactoring the handling of operation contexts in the
promptflow
package. The most significant changes include the addition of acopy
method to theOperationContext
class, the introduction of aset_instance
class method to the same class, and changes to theexec_line_async
and_update_operation_context
methods in theFlowExecutor
class to utilize these new methods.Here is a breakdown of the key changes:
Changes to
OperationContext
class insrc/promptflow/promptflow/_core/operation_context.py
:copy
method has been added to theOperationContext
class, which creates a copy of the current operation context and returns it. This method also ensures that a copy of the_OTEL_ATTRIBUTES
is made.set_instance
class method has been introduced. This method allows setting a new instance of the operation context.Changes to
FlowExecutor
class insrc/promptflow/promptflow/executor/flow_executor.py
:exec_line_async
method, theOperationContext
's newcopy
method is used to create a copy of the original operation context._update_operation_context
method has been significantly simplified. Instead of manually reverting changes to the operation context, it now simply restores the original context using theOperationContext
'sset_instance
method.These changes simplify the code and make the handling of operation contexts more robust and less error-prone.
All Promptflow Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines