Thread
#prefect-community
    a

    An Hoang

    1 year ago
    good morning! What is the best way to parameterize Result location using Flow Parameter? Currently, I have, both at the flow and task level:
    tsv_result_partial = partial(LocalResult, dir="./test_prefect", serializer = PandasSerializer("csv",
                                                                             serialize_kwargs={"sep":"\t", "index": False},
                                                                             deserialize_kwargs={"sep": "\t"}))
    
    parquet_result_partial = partial(LocalResult, dir="./test_prefect", serializer = PandasSerializer("parquet"))
    
    @task_no_checkpoint(target=search_result_df_file_name, result = tsv_result_partial())
    def example_tsv_result_task:
    
    @task_no_checkpoint(target=another_file_name, result = parquet_result_partial())
    def example_parquet_result_task:
    
    with Flow("test", result=LocalResult("./test_prefect")) as flow:
        param1 = Parameter()
        param2 = Parameter()
    I want the outermost directory to be
    result_folder/param1/param2
    . How to achieve this?
    Kevin Kho

    Kevin Kho

    1 year ago
    Hey @An Hoang, have you seen the docs on templating result locations? You can use parameters
    a

    An Hoang

    1 year ago
    somehow I missed this! Sorry for the silly question!!!
    Kevin Kho

    Kevin Kho

    1 year ago
    No worries!
    a

    An Hoang

    1 year ago
    @Kevin Kho sorry so actually I need to pull
    var1
    ,
    var2
    from a task's result variable. should I put those in the
    context
    to make them available for templating?
    Kevin Kho

    Kevin Kho

    1 year ago
    Ah that’s harder because the result is instantiated. I would suggest you don’t do
    @task(…result=Result())
    , you would instead need to use the Result inside your task
    @task
    def abc()
        x = 123
        s3_res = S3Result(location=f"some_location/x.txt",...,...)
        s3_res.write()
        return x
    and then in the downstream task, you need to read it the same way