Skip to content
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

Merged
merged 3 commits into from
Oct 31, 2023

Conversation

jhamon
Copy link
Collaborator

@jhamon jhamon commented Oct 26, 2023

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:

  • Go back to generating the core with openapi 5.2.0 (same version as before, e.g. on main)
    • Everything under pinecone/core is generated using openapi and don't need to be specifically reviewed. This is like 90% of the files changed.
  • Use a template override in the generation step (handled in a private repo) to adjust the urllib3 getheaders() usage and avoid spamming those deprecation notices.
    • Notice that generated rest.py is using correct syntax for getting headers in urllib3
  • Fix tests that broke along the way, mostly due to changes in package structure used by the generated code.
  • Remove dependencies from pyproject.toml that were added when previously going from openapi 5.2.0 => 7.0.1 (pydantic, aenum)

Type of Change

  • None of the above: Update generated code, change dependencies

Follow-up needed

  • Docs build broken. By the looks of it, it seems related to numpy. But I want to remove numpy in a follow-up diff anyway so I may merge with this build failing for now.

@jhamon jhamon changed the title [WIP] Downgrade to openapi 5.2, add template overrides Downgrade to openapi 5.2, add template overrides Oct 30, 2023
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)
Copy link
Collaborator Author

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.

Comment on lines 70 to 76
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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

@jhamon jhamon Oct 30, 2023

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. 🤦

Copy link
Contributor

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. 🧪

@jhamon jhamon marked this pull request as ready for review October 30, 2023 19:13
Copy link
Contributor

@austin-denoble austin-denoble left a 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. :shipit:

tests/unit/test_control.py Show resolved Hide resolved
@@ -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)
Copy link
Contributor

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. 🧪

@austin-denoble
Copy link
Contributor

The docs build failure is confusing to me since we're also running poetry install for the testing steps and that seems to complete fine, and I don't think they use differing dependencies.

Copy link
Contributor

@rohanshah18 rohanshah18 left a 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!

@jhamon jhamon merged commit 70c80a8 into spruce Oct 31, 2023
5 of 6 checks passed
@jhamon jhamon deleted the jhamon/template-overrides branch October 31, 2023 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants