-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Downgrade to openapi 5.2, add template overrides #229
Conversation
self.urllib3_response = resp | ||
self.status = resp.status | ||
self.reason = resp.reason | ||
self.data = resp.data | ||
|
||
def getheaders(self): | ||
"""Returns a dictionary of the response headers.""" | ||
return self.urllib3_response.headers | ||
return self.urllib3_response.getheaders() | ||
|
||
def getheader(self, name, default=None): | ||
"""Returns a given response header.""" | ||
return self.urllib3_response.headers.get(name, default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return self.urllib3_response.headers.get(name, default)
is not showing as a change because it was handled correctly in the 7.0.1 generator that we are downgrading from. But the fact it is not changed means my template override was successfully used; without this template override, openapi 5.2.8 generates return self.urllib3_response.getheader(name, default)
which causes a large amount of runtime deprecation notices to appear.
def parse_query_response(response: QueryResponse, unary_query: bool): | ||
if unary_query: | ||
response.results = None | ||
response._data_store.pop("results", None) | ||
else: | ||
response.matches = None | ||
response.namespace = None | ||
response._data_store.pop("matches", None) | ||
response._data_store.pop("namespace", None) | ||
return response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this at all, but I brought it back from main
to get some tests passing. It seems this thing is supposed to return a different data shape depending on what query parameters were used, which is a terrible design. But not something I want to address right now in this diff with all the generated changes.
@@ -3,7 +3,6 @@ | |||
import pytest | |||
|
|||
import pinecone | |||
from pinecone.config import PineconeConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this wasn't being used, so I deleted it.
@@ -24,43 +23,24 @@ def test_passing_host(self): | |||
(-1, [{"status": {"ready": False}}], 0, 0), | |||
]) | |||
def test_create_index_with_timeout(self, mocker, timeout_value, describe_index_responses, expected_describe_index_calls, expected_sleep_calls): | |||
mocker.patch.object(IndexOperationsApi, 'describe_index', side_effect=describe_index_responses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IndexOperationsApi class generated by openapi 5.2.8 can't be mocked in the normal way because almost all of its methods are attributes defined at runtime from within __init__()
. I'm not a mocker guru by any means, but the only way I could get this working was to grab the instance of IndexOperationsApi being used by the pinecone client and monkey patch that directly. 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's seems like an extremely annoying way to set up a class. Ultimately this seems fine, we do what we can with mocks. 🧪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks a ton for taking this on to get things back in place to avoid the dependency hell problem.
@@ -24,43 +23,24 @@ def test_passing_host(self): | |||
(-1, [{"status": {"ready": False}}], 0, 0), | |||
]) | |||
def test_create_index_with_timeout(self, mocker, timeout_value, describe_index_responses, expected_describe_index_calls, expected_sleep_calls): | |||
mocker.patch.object(IndexOperationsApi, 'describe_index', side_effect=describe_index_responses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's seems like an extremely annoying way to set up a class. Ultimately this seems fine, we do what we can with mocks. 🧪
The docs build failure is confusing to me since we're also running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for making this change!
Problem
Recent versions of openapi generator have added dependencies we don't want to take on, especially
pydantic
v1. Pydantic v2 has been out for a while and we think this is very likely to lead to dependency clashes for some users.Solution
The reason we updated in the first place was to avoid generating code that emitted urllib3 deprecation notices. In this PR, I downgrade to the previously used 5.2.0 generator version and address the urllib3 error using template overrides in the generation step.
In this diff:
pinecone/core
is generated using openapi and don't need to be specifically reviewed. This is like 90% of the files changed.rest.py
is using correct syntax for getting headers in urllib3pyproject.toml
that were added when previously going from openapi 5.2.0 => 7.0.1 (pydantic, aenum)Type of Change
Follow-up needed