fix: preserve file batch id when polling completes#3238
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7135072c9b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return construct_type_unchecked( | ||
| value={ | ||
| **data, | ||
| "id": batch_id, | ||
| "object": "vector_store.files_batch", | ||
| "vector_store_id": vector_store_id, | ||
| }, | ||
| type_=VectorStoreFileBatch, | ||
| ) |
There was a problem hiding this comment.
Keep strict validation for coerced poll responses
When poll() receives a vector_store payload, this path builds VectorStoreFileBatch via construct_type_unchecked, which bypasses _strict_response_validation entirely. That means clients that explicitly enabled strict validation can silently accept malformed fields (wrong enum/value types) in this branch instead of getting a validation error, unlike the normal response.parse() path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Nice catch — I switched the coerced vector_store poll path to run back through the client response processor so strict validation still applies, and added sync/async regression coverage for the malformed payload case. Updated in 0e79e20.
Changes being requested
Fixes #2724.
vector_stores.file_batches.poll()can receive a completed vector store payload from the poll endpoint. In that case, coerce the final payload back to aVectorStoreFileBatchwith the requested batch id/vector store id so the helper returns the batch the caller polled for.Additional context & links
Added sync and async regression coverage for a completed vector store-shaped poll response.
Tests run:
PYTHONPATH=src pytest tests/api_resources/vector_stores/test_file_batches.py::test_poll_coerces_completed_vector_store_response tests/api_resources/vector_stores/test_file_batches.py::test_async_poll_coerces_completed_vector_store_response -q -o addopts="" PYTHONPATH=src python3 -m mypy src/openai/resources/vector_stores/file_batches.py --ignore-missing-imports PYTHONPATH=src python3 -m ruff check src/openai/resources/vector_stores/file_batches.py tests/api_resources/vector_stores/test_file_batches.py