Skip to content

Change from aiohttp to httpx #598

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Change from aiohttp to httpx #598

wants to merge 2 commits into from

Conversation

ponyisi
Copy link
Collaborator

@ponyisi ponyisi commented May 22, 2025

We were using both aiohttp and httpx for connections to the backend. Standardize on httpx (which has, currently, better free-thread support).

@ponyisi ponyisi requested a review from Copilot May 22, 2025 20:58
Copy link

codecov bot commented May 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.31%. Comparing base (2e24a67) to head (99504c5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #598      +/-   ##
==========================================
+ Coverage   96.20%   96.31%   +0.10%     
==========================================
  Files          29       29              
  Lines        1870     1870              
==========================================
+ Hits         1799     1801       +2     
+ Misses         71       69       -2     
Flag Coverage Δ
unittests 96.31% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Standardize on httpx by replacing aiohttp-based clients and retries with httpx.AsyncClient and httpx_retries.

  • Swap out aiohttp.ClientSession/RetryClient for httpx.AsyncClient with RetryTransport
  • Update all response checks to use status_code and JSON decoding to use JSONDecodeError
  • Adjust tests to mock httpx client methods and remove context‐manager mocks

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/test_servicex_adapter.py Mocked ClientSession.get/post/delete, switched to JSONDecodeError
servicex/servicex_adapter.py Replaced aiohttp imports and retries with httpx client and retry transport
pyproject.toml Removed aiohttp-retry dependency, added httpx_retries
Comments suppressed due to low confidence (1)

servicex/servicex_adapter.py:53

  • httpx.Response.json() is synchronous, so await r.json() will error; call r.json() directly (and similarly remove await for other .json() calls).
o = await r.json()

error_message = await _extract_message(r)
raise RuntimeError(
"ServiceX WebAPI Error during transformation "
f"submission: {r.status_code} - {error_message}"
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

The error raised in get_transforms mentions 'submission' but this method retrieves transforms; update the message to reflect retrieval (e.g., 'retrieval').

Suggested change
f"submission: {r.status_code} - {error_message}"
f"retrieval: {r.status_code} - {error_message}"

Copilot uses AI. Check for mistakes.

import httpx
from aiohttp_retry import RetryClient, ExponentialRetry, ClientResponse
from aiohttp import ContentTypeError
from httpx import AsyncClient as ClientSession, Response
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

[nitpick] Aliasing httpx.AsyncClient as ClientSession can be confusing given its similarity to aiohttp; consider using a distinct alias like AsyncClient for clarity.

Suggested change
from httpx import AsyncClient as ClientSession, Response
from httpx import AsyncClient, Response

Copilot uses AI. Check for mistakes.

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.

1 participant