This commit is contained in:
Mrunmayee Daware 2026-10-27 02:26:00 +00:00 • committed by GitHub
commit ed2e84de7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View file

@ -987,7 +987,7 @@ def image_edit(
@client
async def aimage_edit(
image: FileTypes | list[FileTypes],
image: FileTypes | list[FileTypes] | None,
model: str,
prompt: str,
mask: str | None = None,
@ -1027,7 +1027,7 @@ async def aimage_edit(
model=model, api_base=local_vars.get("base_url", None)
)
images: Final = image if isinstance(image, list) else [image]
images: Final = image if isinstance(image, list) else ([image] if image is not None else [])
func: Final = partial(
image_edit,

View file

@ -375,3 +375,22 @@ async def test_async_transform_image_edit_request_downloads_only_the_first_url_o
assert fetched == ["https://cdn.example/a.png"]
assert base64.b64decode(data["input_image"]) == b"first-bytes"
async def test_aimage_edit_none_image_raises_bad_request(monkeypatch):
"""aimage_edit with image=None must surface a clean 400, not an APIConnectionError.
Regression test: the sync `image_edit` normalizes ``image=None`` to ``[]`` while
`aimage_edit` used to build ``[None]``, which crashed the BFL handler with
"Unsupported image type: <class 'NoneType'>".
"""
import litellm
monkeypatch.setenv("BFL_API_KEY", "test-key")
with pytest.raises(litellm.BadRequestError, match="No image provided"):
await litellm.aimage_edit(
model="black_forest_labs/flux-kontext-pro",
prompt="make it blue",
image=None,
)