[Fix] openapi_config deprecation warning incorrectly shown #327
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
A deprecation warning about openapi_config was appearing even when users were not passing in that keyword parameter.
Solution
One of the things that makes the
openapi_config
object (instance ofOpenApiConfiguration
, a generated class) difficult to work with is that it carries a large amount of state; some of the fields inside of it are essentially constant (e.g. API key header) and others need to be adjusted based on which index you are trying to upsert/query/etc from. But you can't simply update those host values because multipleIndex
client objects could be sharing the same object reference. Consequently, acopy()
method was added to make a deepcopy of this object before modifying any configuration properties when targeting an index.For similar reasons, the same
copy()
method was being invoked when users passed in anopenapi_config
object as a kwarg toPinecone(openapi_config=config, api_key='key')
. This object was traditionally used as a vehicle for proxy configuration but needed to be merged with other configuration information, and the copy method ensures those changes are isolated from any other references to the object passed by the user.Anyway, the deprecation notice was erroneously added inside the copy method even though it has these two very different use cases and only one of those use cases make sense for the warning notice to appear. To fix the issue, we simply migration the warning notice into the constructor method of the
Pinecone
class. This__init__()
method is only invoked when creating the client, there's no concern about code reuse causing the notice to appear at other times.Type of Change