Skip to content

Commit d864f65

Browse files
authored
[Fix] openapi_config deprecation warning incorrectly shown (#327)
## 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 of `OpenApiConfiguration`, 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 multiple `Index` client objects could be sharing the same object reference. Consequently, a `copy()` 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 an `openapi_config` object as a kwarg to `Pinecone(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 - [x] Bug fix (non-breaking change which fixes an issue)
1 parent f229f45 commit d864f65

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pinecone/config/openapi.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import certifi
55
import socket
66
import copy
7-
import warnings
87

98
from urllib3.connection import HTTPConnection
109

@@ -34,7 +33,6 @@ def copy(cls, openapi_config: OpenApiConfiguration, api_key: str, host: str) ->
3433
we don't modify those settings.
3534
'''
3635
copied = copy.deepcopy(openapi_config)
37-
warnings.warn("Passing openapi_config is deprecated and will be removed in a future release. Please pass settings such as proxy_url, proxy_headers, ssl_ca_certs, and ssl_verify directly to the Pinecone constructor as keyword arguments. See the README at https://github.com/pinecone-io/pinecone-python-client for examples.", DeprecationWarning)
3836

3937
copied.api_key = {"ApiKeyAuth": api_key}
4038
copied.host = host

pinecone/control/pinecone.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
import warnings
23
from typing import Optional, Dict, Any, Union, List, cast, NamedTuple
34

45
from .index_host_store import IndexHostStore
@@ -174,8 +175,6 @@ def __init__(
174175
pc.list_indexes()
175176
176177
```
177-
178-
179178
"""
180179
if config:
181180
if not isinstance(config, Config):
@@ -194,6 +193,9 @@ def __init__(
194193
**kwargs
195194
)
196195

196+
if kwargs.get("openapi_config", None):
197+
warnings.warn("Passing openapi_config is deprecated and will be removed in a future release. Please pass settings such as proxy_url, proxy_headers, ssl_ca_certs, and ssl_verify directly to the Pinecone constructor as keyword arguments. See the README at https://github.com/pinecone-io/pinecone-python-client for examples.", DeprecationWarning)
198+
197199
self.openapi_config = ConfigBuilder.build_openapi_config(self.config, **kwargs)
198200
self.pool_threads = pool_threads
199201

0 commit comments

Comments
 (0)