-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""This is a regression test for https://github.com/PrefectHQ/prefect/issues/15747""" | ||
|
||
from typing import Tuple | ||
|
||
from prefect import flow, task | ||
from prefect.client.schemas.objects import FlowRun | ||
from prefect.context import get_run_context | ||
from prefect.runtime import task_run | ||
|
||
|
||
def generate_task_run_name() -> str: | ||
return f'{task_run.task_name} - input: {task_run.parameters["input"]["number"]}' | ||
|
||
|
||
@task(log_prints=True, task_run_name=generate_task_run_name) | ||
def increment_number(input: dict) -> dict: | ||
input["number"] += 1 | ||
input["name"] = get_run_context().task_run.name | ||
print(f"increment_number - result: {input['number']}") | ||
return input | ||
|
||
|
||
@flow | ||
def double_increment_flow() -> Tuple[list, FlowRun]: | ||
inputs = [ | ||
{"number": 1, "is_even": False}, | ||
{"number": 2, "is_even": True}, | ||
] | ||
|
||
first_increment = increment_number.map(input=inputs) | ||
second_increment = increment_number.map(input=first_increment) | ||
final_results = second_increment.result() | ||
print(f"Final results: {final_results}") | ||
return final_results | ||
|
||
|
||
async def test_flow_with_mapped_tasks(): | ||
results = double_increment_flow() | ||
assert results == [ | ||
{"number": 3, "is_even": False, "name": "increment_number - input: 2"}, | ||
{"number": 4, "is_even": True, "name": "increment_number - input: 3"}, | ||
] |