AsyncOpenAI.responses.stream() silently skips input validation due to stale isinstance(input, NotGiven) check
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
El error está en src/openai/lib/_response_resources.py, en async_stream(): la comprobación isinstance(input, NotGiven) cerca de la línea 587 y la comprobación isinstance(response_id, Omit) cerca de la línea 650 deberían coincidir con el helper is_given() que ya usa el stream() síncrono. Empieza leyendo el stream() síncrono alrededor de las líneas 412 y 477 para ver el patrón. Está terminado cuando AsyncOpenAI lanza el mismo ValueError que OpenAI cuando se omite input, y un test cubre ambos casos: el caso omit y el caso NOT_GIVEN.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
In src/openai/lib/_response_resources.py, async_stream() (backing AsyncOpenAI.responses.stream()) checks:
- Line 587:
if isinstance(input, NotGiven): - Line 650:
if isinstance(response_id, Omit):
However, both input and response_id default to omit (an instance of Omit, not NotGiven), and isinstance(omit, NotGiven) is False.
As a result:
- Calling
async_client.responses.stream(model="gpt-4o-mini")withoutinputsilently bypassesValueError("input must be provided when creating a new response"), returning anAsyncResponseStreamManagerwrapping a liveresource.create(input=omit, ...)coroutine (which dispatches an invalidPOST /v1/responsesrequest when entered, or emitsRuntimeWarning: coroutine 'AsyncResponses.create' was never awaitedif not entered). - Passing legacy
NOT_GIVENasresponse_idsimilarly bypasses line 650 (isinstance(response_id, Omit)), failing only later insideretrieve()upon__aenter__instead of failing fast at call time.
By contrast, sync stream() in the same file uses if not is_given(input): (line 412) and if not is_given(response_id): (line 477), and async_stream() itself uses if not is_given(model): three lines below (line 590).
To Reproduce
- Instantiate both
OpenAIandAsyncOpenAI. - Call
.responses.stream(model="gpt-4o-mini")withoutinput. - Observe that
OpenAIimmediately raisesValueError("input must be provided when creating a new response"), whileAsyncOpenAIreturns anAsyncResponseStreamManagerwithout raising.
Code snippets
from openai import AsyncOpenAI, OpenAI
from openai._types import NOT_GIVEN
sync_client = OpenAI(api_key="test-key")
async_client = AsyncOpenAI(api_key="test-key")
# Sync raises ValueError as expected:
try:
sync_client.responses.stream(model="gpt-4o-mini")
except ValueError as exc:
print("sync:", exc)
# sync: input must be provided when creating a new response
# Async silently bypasses validation because isinstance(omit, NotGiven) is False:
mgr = async_client.responses.stream(model="gpt-4o-mini")
print("async returned:", type(mgr).__name__)
# async returned: AsyncResponseStreamManager
mgr._AsyncResponseStreamManager__api_request.close()
# Same for legacy NOT_GIVEN on response_id:
mgr2 = async_client.responses.stream(response_id=NOT_GIVEN)
print("async response_id=NOT_GIVEN returned:", type(mgr2).__name__)
# async response_id=NOT_GIVEN returned: AsyncResponseStreamManager
mgr2._AsyncResponseStreamManager__api_request.close()
Suggested fix in src/openai/lib/_response_resources.py:
tools = _make_tools(tools)
if len(new_response_args_names) > 0:
- if isinstance(input, NotGiven):
+ if not is_given(input):
raise ValueError("input must be provided when creating a new response")
@@ -647,7 +647,7 @@
starting_after=None,
)
else:
- if isinstance(response_id, Omit):
+ if not is_given(response_id):
raise ValueError("response_id must be provided when streaming an existing response")
OS
macOS
Python version
Python 3.14
Library version
openai v3.57.0 (main@f63f14b)
- Lenguaje dominante
- Python
- Estrellas
- 32.2k
- Forks
- 5.8k
- Merge medio
- 12 h 29 min
- PR fusionados (30 d)
- 112
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de openai/openai-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
openai/openai-python#4338 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
openai/openai-python#4337 ·
Los mantenedores suelen responder en 1 día
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersPosiblemente ocupada @Rewaskc02-lang la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4311 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4310 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
openai/openai-python#4309 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de openai/openai-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
bad-antics/lateralus-lang#1140 ·
Los mantenedores suelen responder en 4 días
-
Groq: SQL fallback call sends tools with response_format, so a failed tool loop never recoversAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 3 días
-
fixture good first issue help wanted vendor:cisco
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100