PrefectHQ
prefect
BlogDocsChangelog

fix: defer forward reference resolution in ValidatedFunction

#19452
Comparing
fix/19447-forward-references
(
680f8e7
) with
main
(
6e30579
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
+1%
460.8 µs458.3 µs
bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s

Ignored

bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
0%
107.6 ms107.5 ms
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-3%
158.1 ms163 ms
bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1.1 s1.1 s
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+8%
5.7 ms5.3 ms
bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+1%
165.2 ms162.9 ms
bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+9%
6.3 ms5.7 ms

Commits

Click on a commit to change the comparison range
Base
main
6e30579
+0.24%
fix: defer forward reference resolution in ValidatedFunction closes #19447 When using `from __future__ import annotations`, the `@flow` decorator was failing if a forward-referenced Pydantic model was defined after the function using it. The issue occurred because ValidatedFunction tried to resolve forward references at decoration time by calling `model_rebuild()`, but the referenced types didn't exist in the function's `__globals__` yet. This fix: - Tracks deferred rebuilds with `_needs_rebuild` flag to avoid performance overhead - Only calls `model_rebuild()` once during first validation if needed - Catches NameError/AttributeError during initial model_rebuild attempt - Extended test coverage to ensure no rebuilds happen when not needed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
680f8e7
2 days ago
by zzstoatzz
© 2025 CodSpeed Technology
Home Terms Privacy Docs