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
This commit is contained in:
Daniel Han 2026-06-24 03:47:35 -07:00 committed by GitHub
commit 7a25266203
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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")