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

Pass endpoint_id and path_parts to transport #2457

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
elastic-transport>=8.0.0b1, <9
# TODO switch back to elastic-transport>=8,<9 between elastic-transport release and elasticsearch-py release
elastic-transport @ git+https://github.com/elastic/elastic-transport-python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely remember some pain in specifying git urls without an hash, like when trying to upgrade a package checked out from git.
BTW you didn't release a elastic-transport-python because you want to check that all layers are working right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I don't intend to release anything with git dependencies. Maybe I should use a pre-release instead though!

requests>=2, <3
aiohttp
pytest
Expand Down Expand Up @@ -28,4 +29,4 @@ protobuf<4; python_version<="3.7"
# Override Read the Docs default (sphinx<2 and sphinx-rtd-theme<0.5)
sphinx>2
sphinx-rtd-theme>0.5
sphinx-autodoc-typehints
sphinx-autodoc-typehints
14 changes: 13 additions & 1 deletion elasticsearch/_async/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> ApiResponse[Any]:
if headers:
request_headers = self._headers.copy()
Expand Down Expand Up @@ -292,6 +294,8 @@ def mimetype_header_to_compat(header: str) -> None:
retry_on_status=self._retry_on_status,
retry_on_timeout=self._retry_on_timeout,
client_meta=self._client_meta,
endpoint_id=endpoint_id,
path_parts=path_parts,
)

# HEAD with a 404 is returned as a normal response
Expand Down Expand Up @@ -383,9 +387,17 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> ApiResponse[Any]:
# Use the internal clients .perform_request() implementation
# so we take advantage of their transport options.
return await self._client.perform_request(
method, path, params=params, headers=headers, body=body
method,
path,
params=params,
headers=headers,
body=body,
endpoint_id=endpoint_id,
path_parts=path_parts,
)
14 changes: 13 additions & 1 deletion elasticsearch/_sync/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> ApiResponse[Any]:
if headers:
request_headers = self._headers.copy()
Expand Down Expand Up @@ -292,6 +294,8 @@ def mimetype_header_to_compat(header: str) -> None:
retry_on_status=self._retry_on_status,
retry_on_timeout=self._retry_on_timeout,
client_meta=self._client_meta,
endpoint_id=endpoint_id,
path_parts=path_parts,
)

# HEAD with a 404 is returned as a normal response
Expand Down Expand Up @@ -383,9 +387,17 @@ def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> ApiResponse[Any]:
# Use the internal clients .perform_request() implementation
# so we take advantage of their transport options.
return self._client.perform_request(
method, path, params=params, headers=headers, body=body
method,
path,
params=params,
headers=headers,
body=body,
endpoint_id=endpoint_id,
path_parts=path_parts,
)
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
if package == package_name or package.startswith(package_name + ".")
]

install_requires = ["elastic-transport>=8,<9"]
# TODO switch back to elastic-transport>=8,<9 between elastic-transport release and elasticsearch-py release
install_requires = [
"elastic-transport @ git+https://github.com/elastic/elastic-transport-python"
]
async_requires = ["aiohttp>=3,<4"]

setup(
Expand Down
20 changes: 20 additions & 0 deletions test_elasticsearch/test_client/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def test_options_passed_to_perform_request(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
}

# Can be overwritten with .options()
Expand All @@ -160,6 +162,8 @@ def test_options_passed_to_perform_request(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
"request_timeout": 1,
"max_retries": 2,
"retry_on_status": (404,),
Expand All @@ -185,6 +189,8 @@ def test_options_passed_to_perform_request(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
"request_timeout": 1,
"max_retries": 2,
"retry_on_status": (404,),
Expand Down Expand Up @@ -212,6 +218,8 @@ async def test_options_passed_to_async_perform_request(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
}

# Can be overwritten with .options()
Expand All @@ -230,6 +238,8 @@ async def test_options_passed_to_async_perform_request(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
"request_timeout": 1,
"max_retries": 2,
"retry_on_status": (404,),
Expand All @@ -255,6 +265,8 @@ async def test_options_passed_to_async_perform_request(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
"request_timeout": 1,
"max_retries": 2,
"retry_on_status": (404,),
Expand Down Expand Up @@ -390,6 +402,8 @@ def test_options_timeout_parameters(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
"request_timeout": 1,
"max_retries": 2,
"retry_on_status": (404,),
Expand Down Expand Up @@ -419,6 +433,8 @@ def test_options_timeout_parameters(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
"request_timeout": 2,
"max_retries": 3,
"retry_on_status": (400,),
Expand All @@ -443,6 +459,8 @@ def test_options_timeout_parameters(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
}

client = Elasticsearch(
Expand All @@ -464,6 +482,8 @@ def test_options_timeout_parameters(self):
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
},
"body": None,
"endpoint_id": "indices.get",
"path_parts": {"index": "test"},
"request_timeout": 1,
"max_retries": 2,
"retry_on_status": (404,),
Expand Down