Hi community, I seem to be completely misundersta...
# prefect-community
j
Hi community, I seem to be completely misunderstanding the principle of result within flows. My python code below does not print "just a string" to my prompt. If I check the vars i'm able to disect it down to mijn_flow.result which gives me a uniterable object.
Copy code
from prefect import task, flow
import time
@flow
def mijn_flow ():
    return("just a string")

print(mijn_flow())
The output is: 135451.255 | INFO | prefect.engine - Created flow run 'brainy-parakeet' for flow 'mijn-flow' 135451.271 | INFO | Flow run 'brainy-parakeet' - Using task runner 'ConcurrentTaskRunner' 135451.302 | WARNING | Flow run 'brainy-parakeet' - No default storage is configured on the server. Results from this flow run will be stored in a temporary directory in its runtime environment. 135451.443 | INFO | Flow run 'brainy-parakeet' - Finished in state Completed() Completed() Can you point me into the correct direction? I'm trying to access the return object of my flow (which is a string in this case).
1
a
Can you explain what you're trying to accomplish? I cannot reproduce your issue to configure storage, check https://orion-docs.prefect.io/concepts/storage/
j
Yes, I'm trying to get the script to print "just a string" instead of the completed() state
I could turn the flow into a variable and call the result var
Copy code
result = mijn_flow()
print(result.result)
But this gives me this: <bound method State.result of Completed(message=None, type=COMPLETED, result='just a string')>
I'm trying to get to the result='just a string' part
It seems like print(result.result('Completed()')) gives me my desired outcome. Is this the correct way to get to it?
Copy code
from prefect import task, flow
import time
@flow
def mijn_flow ():
    return("just a string")

result = mijn_flow()
print(result.result('Completed()'))
Is working fine, it just feels sloppy for some reason.
a
oh sorry, I misunderstood using .result() is enough:
Copy code
@flow
def mijn_flow():
    return "just a string"


if __name__ == "__main__":
    flow_state = mijn_flow()
    string = flow_state.result()
    print(string)
but we are aware that adding .result() anytime you want to access the actual data may be a bit cumbersome and Michael is currently looking into it
j
Nice, this is what i was looking for. Thanks Anna!🙏
🙌 1