in prefect 1, how to return a value from a flow? ...
# prefect-community
j
in prefect 1, how to return a value from a flow? im calling flows via
create_flow_run
and i want to pass what i generate in the flow to a subsequent flow
✅ 2
k
Hi Jon, I think you'll need to configure results and then you'll be able to grab the results from that
j
thanks @Kalise Richmond! is there a way that i can access the flow's results in memory? writing to a file is too heavy duty
perhaps there's a way to search a flow's state by uuid?
k
hey Jon, are you just looking to pass the state or are you trying to pass a value from the first flow. Here's an example that might help
j
this is what i'm looking for, but the example is a bit confusing. where does the task slug come from?
Copy code
"create_some_data-1"
nvm, i have to add it
but maybe i'm doing something wrong? Seems we can't find the slug?
Copy code
Error during execution of task: ValueError("No task runs found while querying for task runs where {'task': {'slug': {'_eq': 'bronze_file'}}, 'flow_run_id': {'_eq': '5720e378-3b21-4674-8c61-198aa5951f6c'}, 'map_index': {'_eq': -1}}")
Copy code
@prefect.task(slug="bronze_file")
def generate_bronze_file():
what is the "-1" coming from here?
"create_some_data-1"
k
I believe every instance of a task gets the number appended because you can map over tasks.
j
ok, so if i call the task just once in my flow it'll have a "-1"?
k
I think so. It's been a while since I've tried it out
looks like there is a
map_index
field you can use as well https://docs-v1.prefect.io/api/latest/tasks/prefect.html#get-task-run-result
j
my task isn't mapped?
it works by appending "-1"
🎉 1
IMO a bit too magical 🧙
also the docs say that slugs are stable : `slug (str, optional)`: The slug for this task. Slugs provide a stable ID for tasks so that the Prefect API can identify task run states. If a slug is not provided, one will be generated automatically once the task is added to a Flow.
so kinda confusing the slug actually changes here
but thx for your help
k
Thanks for the feedback. I’ll make sure to let our doc experts know 😃
🙌 1