Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Oct 21, 2024
1 parent 0188601 commit 6f61398
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/prefect/client/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2303,11 +2303,11 @@ async def read_task_run(self, task_run_id: UUID) -> TaskRun:
async def read_task_runs(
self,
*,
flow_filter: FlowFilter = None,
flow_run_filter: FlowRunFilter = None,
task_run_filter: TaskRunFilter = None,
deployment_filter: DeploymentFilter = None,
sort: TaskRunSort = None,
flow_filter: Optional[FlowFilter] = None,
flow_run_filter: Optional[FlowRunFilter] = None,
task_run_filter: Optional[TaskRunFilter] = None,
deployment_filter: Optional[DeploymentFilter] = None,
sort: Optional[TaskRunSort] = None,
limit: Optional[int] = None,
offset: int = 0,
) -> List[TaskRun]:
Expand Down
42 changes: 42 additions & 0 deletions tests/public/flows/test_flow_with_mapped_tasks.py
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"},
]

0 comments on commit 6f61398

Please sign in to comment.