-
Notifications
You must be signed in to change notification settings - Fork 789
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
Revert "refactor loopblock value" #1380
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 |
---|---|---|
|
@@ -47,10 +47,8 @@ | |
from skyvern.forge.sdk.schemas.tasks import Task, TaskOutput, TaskStatus | ||
from skyvern.forge.sdk.workflow.context_manager import BlockMetadata, WorkflowRunContext | ||
from skyvern.forge.sdk.workflow.exceptions import ( | ||
FailedToFormatJinjaStyleParameter, | ||
InvalidEmailClientConfiguration, | ||
InvalidFileType, | ||
NoIterableValueFound, | ||
NoValidEmailRecipient, | ||
) | ||
from skyvern.forge.sdk.workflow.models.parameter import ( | ||
|
@@ -578,17 +576,14 @@ def get_failure_reason(self) -> str | None: | |
class ForLoopBlock(Block): | ||
block_type: Literal[BlockType.FOR_LOOP] = BlockType.FOR_LOOP | ||
|
||
loop_over: PARAMETER_TYPE | None | ||
loop_variable_reference: str | None | ||
loop_over: PARAMETER_TYPE | ||
loop_blocks: list[BlockTypeVar] | ||
|
||
def get_all_parameters( | ||
self, | ||
workflow_run_id: str, | ||
) -> list[PARAMETER_TYPE]: | ||
parameters = set() | ||
if self.loop_over is not None: | ||
parameters.add(self.loop_over) | ||
parameters = {self.loop_over} | ||
|
||
for loop_block in self.loop_blocks: | ||
for parameter in loop_block.get_all_parameters(workflow_run_id): | ||
|
@@ -605,9 +600,6 @@ def get_loop_block_context_parameters(self, workflow_run_id: str, loop_data: Any | |
if isinstance(parameter, ContextParameter): | ||
context_parameters.append(parameter) | ||
|
||
if self.loop_over is None: | ||
return context_parameters | ||
|
||
for context_parameter in context_parameters: | ||
if context_parameter.source.key != self.loop_over.key: | ||
continue | ||
|
@@ -628,44 +620,29 @@ def get_loop_block_context_parameters(self, workflow_run_id: str, loop_data: Any | |
return context_parameters | ||
|
||
def get_loop_over_parameter_values(self, workflow_run_context: WorkflowRunContext) -> list[Any]: | ||
# parse the value from self.loop_variable_reference and then from self.loop_over | ||
if self.loop_variable_reference: | ||
value_template = f'{{{{ {self.loop_variable_reference.strip(" {}")} | tojson }}}}' | ||
try: | ||
value_json = self.format_block_parameter_template_from_workflow_run_context( | ||
value_template, workflow_run_context | ||
) | ||
except Exception as e: | ||
raise FailedToFormatJinjaStyleParameter(value_template, str(e)) | ||
parameter_value = json.loads(value_json) | ||
|
||
elif self.loop_over is not None: | ||
if isinstance(self.loop_over, WorkflowParameter): | ||
parameter_value = workflow_run_context.get_value(self.loop_over.key) | ||
elif isinstance(self.loop_over, OutputParameter): | ||
# If the output parameter is for a TaskBlock, it will be a TaskOutput object. We need to extract the | ||
# value from the TaskOutput object's extracted_information field. | ||
output_parameter_value = workflow_run_context.get_value(self.loop_over.key) | ||
if isinstance(output_parameter_value, dict) and "extracted_information" in output_parameter_value: | ||
parameter_value = output_parameter_value["extracted_information"] | ||
else: | ||
parameter_value = output_parameter_value | ||
elif isinstance(self.loop_over, ContextParameter): | ||
parameter_value = self.loop_over.value | ||
if not parameter_value: | ||
source_parameter_value = workflow_run_context.get_value(self.loop_over.source.key) | ||
if isinstance(source_parameter_value, dict): | ||
if "extracted_information" in source_parameter_value: | ||
parameter_value = source_parameter_value["extracted_information"].get(self.loop_over.key) | ||
else: | ||
parameter_value = source_parameter_value.get(self.loop_over.key) | ||
else: | ||
raise ValueError("ContextParameter source value should be a dict") | ||
if isinstance(self.loop_over, WorkflowParameter): | ||
parameter_value = workflow_run_context.get_value(self.loop_over.key) | ||
elif isinstance(self.loop_over, OutputParameter): | ||
# If the output parameter is for a TaskBlock, it will be a TaskOutput object. We need to extract the | ||
# value from the TaskOutput object's extracted_information field. | ||
output_parameter_value = workflow_run_context.get_value(self.loop_over.key) | ||
if isinstance(output_parameter_value, dict) and "extracted_information" in output_parameter_value: | ||
parameter_value = output_parameter_value["extracted_information"] | ||
else: | ||
raise NotImplementedError() | ||
|
||
parameter_value = output_parameter_value | ||
elif isinstance(self.loop_over, ContextParameter): | ||
parameter_value = self.loop_over.value | ||
if not parameter_value: | ||
source_parameter_value = workflow_run_context.get_value(self.loop_over.source.key) | ||
if isinstance(source_parameter_value, dict): | ||
if "extracted_information" in source_parameter_value: | ||
parameter_value = source_parameter_value["extracted_information"].get(self.loop_over.key) | ||
else: | ||
parameter_value = source_parameter_value.get(self.loop_over.key) | ||
else: | ||
raise ValueError("ContextParameter source value should be a dict") | ||
else: | ||
raise NoIterableValueFound() | ||
raise NotImplementedError | ||
|
||
if isinstance(parameter_value, list): | ||
return parameter_value | ||
|
@@ -748,15 +725,7 @@ async def execute_loop_helper( | |
|
||
async def execute(self, workflow_run_id: str, **kwargs: dict) -> BlockResult: | ||
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. Removing exception handling for |
||
workflow_run_context = self.get_workflow_run_context(workflow_run_id) | ||
try: | ||
loop_over_values = self.get_loop_over_parameter_values(workflow_run_context) | ||
except Exception as e: | ||
return self.build_block_result( | ||
success=False, | ||
failure_reason=f"failed to get loop values: {str(e)}", | ||
status=BlockStatus.failed, | ||
) | ||
|
||
loop_over_values = self.get_loop_over_parameter_values(workflow_run_context) | ||
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. Removing exception handling for |
||
LOG.info( | ||
f"Number of loop_over values: {len(loop_over_values)}", | ||
block_type=self.block_type, | ||
|
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.
Raising
NotImplementedError
instead of a specific exception likeNoIterableValueFound
can make debugging more difficult. Consider using a more descriptive exception to improve error handling and clarity.