Fix Response Info Assignment for Non-Model Return Types (#564)#568
Open
mdelriolanse wants to merge 1 commit intopinecone-io:mainfrom
Open
Fix Response Info Assignment for Non-Model Return Types (#564)#568mdelriolanse wants to merge 1 commit intopinecone-io:mainfrom
mdelriolanse wants to merge 1 commit intopinecone-io:mainfrom
Conversation
) The API clients were failing when attempting to attach `_response_info` to response data that doesn't support attribute assignment. This could occur when: 1. The `return_data` is an empty string 2. The `return_data` is a type that doesn't support `setattr` (e.g., primitives, immutable types) In the async and sync clients, string responses weren't being handled, causing potential failures when the API returns string data that should have response info attached. Added defensive handling for edge cases when attaching `_response_info`: - Added `json` import for parsing string responses - Added comprehensive string handling: - Empty strings are converted to a dict with `_response_info` - Non-empty strings are parsed as JSON; if successful and the result is a dict, `_response_info` is added - Parse failures fall back to returning a dict with just `_response_info` - Wrapped setattr call in try/except to gracefully handle types that don't support dynamic attribute assignment - Prevents runtime errors when API responses are empty strings or unsupported types - Ensures `_response_info` is available when possible, gracefully degraded when not No breaking changes to existing functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The API clients were failing when attempting to attach
_response_infoto response data that doesn't support attribute assignment. This could occur when:return_datais an empty stringreturn_datais a type that doesn't supportsetattr(e.g., primitives, immutable types)In the async and sync clients, string responses weren't being handled, causing potential failures when the API returns string data that should have response info attached.
Solution
Added defensive handling for edge cases when attaching
_response_info:pinecone/openapi_support/api_client.pyandpinecone/openapi_support/asyncio_api_client.pyjsonimport for parsing string responses_response_info_response_infois added_response_infoImpact
_response_infois available when possible, gracefully degraded when notBreaking Changes
No breaking changes to existing functionality