Hi - Is there a way to get the result of a specifi...
# prefect-community
i
Hi - Is there a way to get the result of a specific merge task after running a flow . Similar to this:
flow_state.result[ifelse_return].result
n
Hi @itay livni we’ve got an example here, does this help? https://docs.prefect.io/api/unreleased/tasks/control_flow.html#functions
i
merge
?
n
Copy code
with Flow("My Flow"):
        true_branch = ActionIfTrue()
        false_branch = ActionIfFalse()
        ifelse(CheckCondition(), true_branch, false_branch)

        merged_result = merge(true_branch, false_branch)
i
I need to rephrase the question. How do I access merged result after running "My Flow"
merged_result
is in another file.
get_defs_state.result[merge].result
j
Is that not returning your result? The access pattern from above works for me:
Copy code
In [10]: flow_state.result[merged_result].result
Out[10]: True
Not sure what you mean by
merged_result
being in another file
i
Yes that works when running a flow from the same file the flow is defined in. However if the flow is run from a different file\module then an error (obviously occurs) `Using variable before assignment
I tried get tasks but the merged results was not defined in the flow
j
If you are calling the flow and trying to retrieve the result from a different process then it will need to be persisted somewhere via a result handler https://docs.prefect.io/core/concepts/results.html
The merged result will also only exist on a flow object (if you’re trying to access it that way) once it is run. i.e. importing the flow will not contain the merge result
i
Copy code
# Get Disambiguated Definitions
get_defs_state = get_defs_flow.run(
        parameters=dict(
            term=args.term,node_artifact_id=node_artifact_id,
            node_artifact_flpth=node_artifact_flpth
        )
    )
    get_defs_flow.visualize(flow_state=get_defs_state)

#definitions_df = get_defs_flow.get_tasks()
    definitions_df = get_defs_state.result[definitions_df].result
j
Ah okay I see what you’re trying to do. Now I understand
i
ok cool. So what is the right way to do this
the result handler section does not have any code examples 😞
j
Try:
Copy code
task = get_defs_flow.get_tasks()[...] # get the task
get_defs_state.result[task].result
Where you get the task you want from the list returned by
get_tasks
i
so that task is not in the list. I tried that
neither is merge
j
Hmm weird because it appears in the flow for me:
Copy code
In [21]: flow.get_tasks()
Out[21]:
[<Task: CompareValue: "True">,
 <Task: check>,
 <Task: Merge>,
 <Task: True>,
 <Task: CompareValue: "False">,
 <Task: False>]
If you visualize your flow is the merge task present?
i
yes... That worked 🙂 Not sure why it was failing earlier.
thank you
j
Great! I opened an issue to add some documentation on the result handler page because even though it was unrelated to this we definitely should add some clarity there 🙂
i
yes I looked at if before trying this method to see if it was appropriate and well ...
Thanks again