PrefectHQ
prefect
BlogDocsChangelog

fix: allow pause_flow_run() to pause parent flow when called from task

#19457
Comparing
fix/19435-pause-flow-run-from-task
(
99df9f2
) with
main
(
dd07711
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
0%
462.2 µs461.4 µs
bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s

Ignored

bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1.1 s1.1 s
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+1%
158.7 ms157.7 ms
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
0%
107.3 ms107.6 ms
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-13%
4.9 ms5.7 ms
bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+3%
169.6 ms164.8 ms
bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+2%
6.3 ms6.2 ms

Commits

Click on a commit to change the comparison range
Base
main
dd07711
+0.09%
fix: allow pause_flow_run() to pause parent flow when called from task closes #19435 this pr changes pause_flow_run() to pause the parent flow when called from within a task, instead of raising "cannot pause task runs" error. <details> <summary>context</summary> previously, calling pause_flow_run() from within a task would raise: ``` RuntimeError: Cannot pause task runs. ``` this was overly restrictive since: 1. the function is named pause_flow_run(), not pause_task_run() 2. both FlowRunContext and TaskRunContext are independently active when a task runs inside a flow 3. users reasonably expect to encapsulate approval/pause logic in reusable tasks </details> <details> <summary>changes</summary> **src/prefect/flow_runs.py** - removed the guard that raised RuntimeError when TaskRunContext.get() was truthy - now directly accesses FlowRunContext.get() (which works even inside tasks) to pause the parent flow **tests/test_flow_engine.py** - renamed test_tasks_cannot_be_paused to test_pause_flow_run_from_task_pauses_parent_flow - updated to verify pause works correctly instead of expecting error - added test_pause_flow_run_from_task_with_input to verify pause with wait_for_input works from tasks </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
99df9f2
2 days ago
by zzstoatzz
© 2025 CodSpeed Technology
Home Terms Privacy Docs