MAINT Consolidate duplicate image URL download handling
@nightcityblade is already working on this.
Since Aug 19, 2026.
Assessment
This issue has not been assessed yet.
Description
Is your feature request related to a problem? Please describe.
BaseImageToImageConverter._read_image_from_url_async and ImageCompressionConverter._read_image_from_url_async contain an exact duplicate asynchronous image URL downloader and error wrapper (approximately 19 lines each).
The duplication creates two places to maintain HTTP behavior, response handling, and user-facing RuntimeError semantics. The current implementations are small, but divergence could cause transform converters and image compression to treat the same URL failure differently.
Describe the solution you'd like
Consolidate the shared behavior into one converter-internal asynchronous helper that preserves:
- the existing aiohttp request and response semantics;
- exact error wrapping and message behavior;
- byte-return behavior;
- cancellation and exception propagation;
- compatibility for subclasses of
BaseImageToImageConverter.
Delete the duplicate implementation and have both converter paths use the shared helper. Keep the helper internal unless there is concrete evidence that it should become a supported extension point.
Describe alternatives you've considered, if relevant
Making ImageCompressionConverter inherit from BaseImageToImageConverter would create an artificial type relationship and pull in unrelated behavior. A standalone internal helper is simpler. Keeping both methods is viable but leaves a confirmed duplicate network/error contract.
Additional context
Before changing the method surface, inspect whether external or in-repository subclasses override _read_image_from_url_async. If override compatibility matters, retain a delegating method on the base class rather than removing the hook.
Validation should cover:
- all base image-to-image transform converter tests;
- image compression tests;
- successful URL reads;
- non-success HTTP responses;
- connection and body-read errors;
- exact exception text/type;
- cancellation propagation;
- subclass override compatibility.
This is the lowest-risk candidate of the five, with moderate extension-point risk and a clear deletion/consolidation benefit.
- Dominant language
- Python
- Stars
- 4.5k
- Forks
- 896
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 155
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/PyRIT
-
Bug: triage help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Bug: triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
BUG: ScorerMetrics.to_json() raises TypeError on the trial_scores array ScorerEvaluator attaches Open
Difficulty 3/5 1-2 days Newbie friendliness 78/100
-
Bug: triage help wanted
Difficulty 3/5 1-2 days Newbie friendliness 75/100
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100