Jan

    Jan

    2 months ago
    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.
    from prefect import task, flow
    import time
    @flow
    def mijn_flow ():
        return("just a string")
    
    print(mijn_flow())
    The output is: 13:54:51.255 | INFO | prefect.engine - Created flow run 'brainy-parakeet' for flow 'mijn-flow' 13:54:51.271 | INFO | Flow run 'brainy-parakeet' - Using task runner 'ConcurrentTaskRunner' 13:54:51.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. 13:54:51.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).
    Anna Geller

    Anna Geller

    2 months ago
    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/
    Jan

    Jan

    2 months ago
    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
    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?
    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.
    Anna Geller

    Anna Geller

    2 months ago
    oh sorry, I misunderstood using .result() is enough:
    @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
    Jan

    Jan

    2 months ago
    Nice, this is what i was looking for. Thanks Anna!🙏