fix(image_gen): say the FAL fallback also failed instead of claiming an image was generated

This commit is contained in:
Mariano Nicolini
2026-10-07 18:21:20 -03:00
committed by Mark S.
parent 8d0c59d75c
commit 8daaaca084
2 changed files with 5 additions and 3 deletions

View File

@@ -96,8 +96,8 @@ class TestPluginDispatch:
assert len(fal_calls) == 1 and fal_calls[0]["fal_model"] == ig.DEFAULT_MODEL
assert result["fallback_from"] == "krea"
assert result["fallback_reason"] == "Krea connection error"
assert "FAL" in result["note"]
assert result["success"] is fal_ok
assert ("generated on FAL" if fal_ok else "also failed") in result["note"]
def test_deepinfra_key_alone_does_not_select_image_backend(self, monkeypatch):
"""DeepInfra chat credentials do not imply consent to image billing."""

View File

@@ -813,9 +813,11 @@ def _fall_back_to_fal(raw: str, prompt: str, aspect_ratio: str, sources: dict[st
return raw
logger.warning("Managed Krea refused the request before starting a job; falling back to FAL: %s", result.get("error"))
fal_result = json.loads(image_generate_tool(prompt, aspect_ratio, upscale=sources.get("upscale"), fal_model=DEFAULT_MODEL))
note = (f"Krea was unavailable, so this image was generated on FAL ({DEFAULT_MODEL}) instead."
if fal_result.get("success") else
f"Krea was unavailable and the fallback to FAL ({DEFAULT_MODEL}) also failed.")
fal_result.update(
provider="fal", model=DEFAULT_MODEL, fallback_from="krea", fallback_reason=result.get("error"),
note=f"Krea was unavailable, so this image was generated on FAL ({DEFAULT_MODEL}) instead.")
provider="fal", model=DEFAULT_MODEL, fallback_from="krea", fallback_reason=result.get("error"), note=note)
return json.dumps(fal_result)