Async streaming response wrappers leak an unawaited coroutine when not entered
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Inizia in src/browserbase/_response.py:632-637 e 669-685, confrontando AsyncResponseContextManager con il ResponseContextManager sincrono. Riproduci il caso dell’issue in cui il manager viene scartato senza entrarvi, quindi aggiungi un test del ciclo di vita che mostri che non viene emesso alcun avviso relativo a una coroutine non attesa e che l’ingresso nel manager esegue comunque la richiesta prevista.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
The async .with_streaming_response wrappers create the endpoint coroutine immediately, before the returned context manager is entered. If the context manager is conditionally discarded or never entered, Python emits RuntimeWarning: coroutine ... was never awaited.
This differs from the synchronous wrapper, which stores a callable and does not invoke the endpoint until __enter__.
Code reference
src/browserbase/_response.py:669-685AsyncResponseContextManagerstores an already-createdAwaitableatsrc/browserbase/_response.py:632-637
Reproduction
import asyncio
import gc
import warnings
from browserbase import AsyncBrowserbase
async def main():
client = AsyncBrowserbase(api_key="test")
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
cm = client.sessions.with_streaming_response.create(project_id="p")
del cm
gc.collect()
await asyncio.sleep(0)
print([str(w.message) for w in caught])
await client.close()
asyncio.run(main())
Actual output includes:
coroutine 'AsyncSessionsResource.create' was never awaited
No HTTP request is needed to reproduce this.
Expected behavior
Creating and discarding an unentered response context manager should not allocate an unawaited coroutine or emit a resource warning. The async manager could retain a callable/partial and invoke it lazily from __aenter__, matching ResponseContextManager.
Why it matters
Warnings are promoted to errors in many test suites, and conditional streaming code can produce noisy, nondeterministic resource warnings. This path currently has no direct lifecycle test.
- Lingua principale
- Python
- Stelle
- 93
- Fork
- 16
- Merge medio
- 11m
- PR unite (30g)
- 3
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di browserbase/sdk-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
browserbase/sdk-python#182 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
browserbase/sdk-python#180 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
browserbase/sdk-python#179 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
browserbase/sdk-python#178 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
browserbase/sdk-python#176 ·
Tutte le issue di browserbase/sdk-python
Issue simili
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
simonw/sqlite-utils#872 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100