Title: Python 3.14 Compatibility: NameError in _outbound_schedule_activity due to eager closure-cell inspection
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
Hướng nghiên cứu
Bắt đầu tại temporalio/worker/_workflow_instance.py, ở _outbound_schedule_activity, và kiểm tra cách handle được run_activity capture trong quá trình xây dựng _ActivityHandle. Tái hiện workflow activity Hello World tối thiểu trong môi trường phát triển Python 3.14, sau đó xác minh rằng việc lên lịch activity hoàn tất mà không có NameError đã được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What are you really trying to do?
I am upgrading a production service to use the latest Python environments (specifically testing against Python 3.14 alpha/dev builds). I encountered a regression where Temporal workflows fail immediately when scheduling activities due to changes in how Python 3.14 handles asyncio.Task initialization and closure cell inspection. I am reporting this so the SDK can be made compatible with the upcoming Python 3.14 release.
Describe the bug
In Python 3.14, any workflow calling await workflow.execute_activity(...) fails with a NameError.
This is caused by a "binding lag" in _workflow_instance.py. The variable handle is annotated but not assigned a value before it is referenced inside the run_activity closure. While previous Python versions (up to 3.13) deferred the inspection of these cells until the coroutine actually executed, Python 3.14’s asyncio.Task constructor (specifically when set_name is called) eagerly inspects the cells. Because the task is created in the same expression that binds the name, the inspection happens while the cell is still empty, triggering the error.
Traceback:
File ".../temporalio/worker/_workflow_instance.py", line 1921, in _outbound_schedule_activity
handle = _ActivityHandle(self, input, run_activity())
File ".../temporalio/worker/_workflow_instance.py", line 3047, in _ActivityHandle.__init__
instance._register_task(self, name=f"activity: {input.activity}")
File ".../temporalio/worker/_workflow_instance.py", line 2458, in _register_task
task.set_name(name)
NameError: cannot access free variable 'handle' where it is not associated with a value in enclosing scope
Minimal Reproduction
- Use a Python 3.14 environment (e.g.,
cgr.dev/chainguard/python:latest-dev). - Run any standard "Hello World" workflow.
- Attempt to execute an activity.
- The worker will catch a
NameErrorduring the_outbound_schedule_activitycall.
The problematic code pattern in _workflow_instance.py:
handle: _ActivityHandle # Created but UNBOUND
async def run_activity() -> Any:
while True:
handle._started = True # Closure reference
...
# Python 3.14 fails here because run_activity()
# is inspected during Task creation inside the _ActivityHandle init
handle = _ActivityHandle(self, input, run_activity())
Environment/Versions
- OS and processor: Linux (verified on x86_64/Aarch64 via Chainguard images)
- Temporal Version: SDK versions 1.21.1 through 1.26.0 (current stable range)
- Python Version: 3.14.0a (early 2026 dev builds)
- Deployment: Docker-based workers
Additional context
A temporary runtime patch confirms that pre-binding the variable resolves the issue:
handle: Optional[_ActivityHandle] = None # Explicit binding fixes the NameError
This issue will likely affect all users as they begin migrating to Python 3.14 later this year, or those using "floating" rolling-release base images in their CI/CD pipelines.
- Ngôn ngữ chính
- Python
- Star
- 1.2k
- Fork
- 241
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 49
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của temporalio/sdk-python
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
temporalio/sdk-python#496 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
temporalio/sdk-python#1890 ·
-
[Bug] Local activity resolutions regrouped on replay since 1.32.0, delivering the wrong payload Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
temporalio/sdk-python#1881 · 1 bình luận ·
-
bug
temporalio/sdk-python#1817 · 1 bình luận · 1 người được giao ·
-
Cloud CI Skips Nexus Tests Đang mở
temporalio/sdk-python#1704 · 1 người được giao ·
Tất cả issue của temporalio/sdk-python
Issue tương tự
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
simonw/sqlite-utils#872 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100