From 7a2526620353acf63009c55cbf031b0c23abefd7 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Wed, 24 Jun 2026 03:47:35 -0700 Subject: [PATCH] Fix _SameTaskStreamingResponse disconnect test bypassing __init__ (#6627) * Fix _SameTaskStreamingResponse disconnect test bypassing __init__ test_same_task_response_closes_body_iterator_on_send_disconnect builds the response via __new__ to skip Starlette's __init__, then wires body_iterator, background, and stream_response by hand. It never set _unstarted_cleanup, so the disconnect-before-first-chunk branch of __call__ raised AttributeError instead of ClientDisconnect, failing the Backend CI "Repo tests (CPU)" job on main. Set response._unstarted_cleanup = None in the manual construction, matching the default __init__ assigns. * Shorten the _unstarted_cleanup comment to one line --- tests/studio/test_stream_cancel_registration_timing.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/studio/test_stream_cancel_registration_timing.py b/tests/studio/test_stream_cancel_registration_timing.py index 33deb7af9d..7cfe9bf32c 100644 --- a/tests/studio/test_stream_cancel_registration_timing.py +++ b/tests/studio/test_stream_cancel_registration_timing.py @@ -411,6 +411,8 @@ def test_same_task_response_closes_body_iterator_on_send_disconnect(): response = m["_SameTaskStreamingResponse"].__new__(m["_SameTaskStreamingResponse"]) response.body_iterator = agen response.background = None + # __new__ bypasses __init__; __call__'s disconnect branch reads _unstarted_cleanup. + response._unstarted_cleanup = None async def stream_response(_send): raise OSError("client disconnected")