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

Fix incompatibility with httpx>=0.28 #52

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 8 additions & 5 deletions src/enlyze/api_clients/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _full_url(self, api_path: str) -> str:
"""Construct full URL from relative URL"""
return str(self._client.build_request("", api_path).url)

def get(self, api_path: str, **kwargs: Any) -> Any:
def get(self, api_path: str | httpx.URL, **kwargs: Any) -> Any:
"""Wraps :meth:`httpx.Client.get` with defensive error handling

:param api_path: Relative URL path inside the API name space (or a full URL)
Expand Down Expand Up @@ -146,11 +146,11 @@ def _has_more(self, paginated_response: R) -> bool:
def _next_page_call_args(
self,
*,
url: str,
url: str | httpx.URL,
params: dict[str, Any],
paginated_response: R,
**kwargs: Any,
) -> tuple[str, dict[str, Any], dict[str, Any]]:
) -> tuple[str | httpx.URL, dict[str, Any], dict[str, Any]]:
r"""Compute call arguments for the next page.

:param url: The URL used to fetch the current page
Expand All @@ -166,7 +166,7 @@ def _next_page_call_args(
"""

def get_paginated(
self, api_path: str, model: type[M], **kwargs: Any
self, api_path: str | httpx.URL, model: type[M], **kwargs: Any
) -> Iterator[M]:
"""Retrieve objects from a paginated ENLYZE platform API endpoint via HTTP GET.

Expand Down Expand Up @@ -196,7 +196,10 @@ def get_paginated(
params = kwargs.pop("params", {})

while True:
response_body = self.get(url, params=params, **kwargs)
# merge query parameters into URL instead of replacing (ref httpx#3364)
url_with_query_params = httpx.URL(url).copy_merge_params(params)

response_body = self.get(url_with_query_params, **kwargs)
try:
paginated_response = self.PaginatedResponseModel.model_validate(
response_body
Expand Down
4 changes: 2 additions & 2 deletions src/enlyze/api_clients/production_runs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def _has_more(self, paginated_response: _PaginatedResponse) -> bool:

def _next_page_call_args(
self,
url: str,
url: str | httpx.URL,
params: dict[str, Any],
paginated_response: _PaginatedResponse,
**kwargs: Any,
) -> tuple[str, dict[str, Any], dict[str, Any]]:
) -> tuple[str | httpx.URL, dict[str, Any], dict[str, Any]]:
next_params = {**params, "cursor": paginated_response.metadata.next_cursor}
return (url, next_params, kwargs)
4 changes: 2 additions & 2 deletions src/enlyze/api_clients/timeseries/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def _has_more(self, paginated_response: _PaginatedResponse) -> bool:
def _next_page_call_args(
self,
*,
url: str,
url: str | httpx.URL,
params: dict[str, Any],
paginated_response: _PaginatedResponse,
**kwargs: Any,
) -> Tuple[str, dict[str, Any], dict[str, Any]]:
) -> Tuple[str | httpx.URL, dict[str, Any], dict[str, Any]]:
next_url = str(paginated_response.next)
return (next_url, params, kwargs)
Loading