Hey everyone _ I was wondering if someone can tell...
# prefect-community
m
Hey everyone _ I was wondering if someone can tell me why the following code runs fine without errors when calling
flow.run()
but
flow.register()
flags an error mainly the healthcheck throws this error - which I see referenced in the documentation … I am using prefect
v0.11.4
Copy code
ValueError: Mapped tasks with custom result locations must include
{filename} as a template in their location.
Please see the code below
Copy code
import os
from prefect import task, Flow
from prefect.engine.results import S3Result


@task
def gen_list():
    return [x for x in range(10)]


@task
def add(x, y):
    return x + y


@task
def multiply(x, y):
    return x * y


result = S3Result(
    bucket=os.environ["AWS_BUCKET"],
    location='prefect-testing/{task_name}/{map_index}.prefect'
)

with Flow('Test Flow', result=result) as flow:
    x = gen_list()
    y = gen_list()
    added = add.map(x, y)
    multiplied = multiply.map(added, added)

# flow runs fine if running locally
flow.run()


"""
flow fails to register
ValueError: Mapped tasks with custom result locations must include
{filename} as a template in their location.
"""
flow.register('Test Project')
n
Hi @Marwan Sarieddine! As the error message mentions, you need to include
{filename}
in the location template for your result. So in this case you'd have something like:
Copy code
# ...imports and tasks

result = S3Result(
  bucket=os.environ["AWS_BUCKET"],
  location="prefect-testing/{task_name}/{file_name}_{map_index}.prefect"
)

# ...
m
Hi @nicholas - yes I understand that I need to update the template to include
{filename}
- but what I don’t understand is why
{filename}
is necessary if flow.run() locally doesn’t throw errors and works fine ?
n
It looks like there's an open issue that touches this and explains why the filename isn't throwing an error locally (it isn't populated); you might add your code to that as well 🙂
m
I see - thanks ! I suppose the answer is here “I don’t think we populate the 
filename
 attribute for local runs”
👍 1
(just added my snippet )
n
Thanks @Marwan Sarieddine!
m
sure - thank you!