[ Bug]: Provider image fallback is dead code — the fallback path is computed but never opened
Current Behavior
GET /provider-containers/{provider_type}/image (and the tenant image route) fall back to /unknown-icon.png when DEFAULT_IMAGE_PATH doesn't exist — the path variable is reassigned and a warning is logged, but the very next line opens the original constant instead of the computed variable:
# keep/api/routes/provider_images.py (get_provider_image)
path = DEFAULT_IMAGE_PATH
if not os.path.exists(path):
fallback_path = "/unknown-icon.png"
logger.warning(
f"Default image not found at {DEFAULT_IMAGE_PATH}, using fallback path: {fallback_path}"
)
path = fallback_path
with open(DEFAULT_IMAGE_PATH, "rb") as f: # <-- ignores `path`, opens DEFAULT_IMAGE_PATH again
return Response(content=f.read(), media_type="image/png")So when the default image is missing, the fallback branch runs (logs the warning) and then open(DEFAULT_IMAGE_PATH) raises FileNotFoundError anyway → the endpoint returns a bare 404 "Default image not found" even though /unknown-icon.png exists on disk. The whole fallback mechanism can never work.
This hits any deployment where DEFAULT_IMAGE_PATH resolves differently between the server process cwd and the baked image layout — the fallback was clearly added for exactly that case (see the warning message), but the bug made it a no-op.
Expected Behavior
When the default image is missing and the fallback file exists, the endpoint should serve the fallback image. Only when neither file exists should it 404.
Steps to Reproduce
- Start the API with
DEFAULT_IMAGE_PATHpointing at a non-existent file, with/unknown-icon.pngpresent. GET /provider-containers/nonexistent-provider/imagefor a provider with no custom image in the DB.- Actual: 404
Default image not found(with a misleading "using fallback path" warning in the log). Expected: 200 with the fallback PNG.
Reproduced with a minimal unit test driving get_provider_image directly: with the current code, the "fallback served when default missing" case raises HTTPException(404); patching with open(path, "rb") makes it return the fallback bytes.
Version
latest (main, commit fe5c896)
Relevant log output
WARNING Default image not found at <DEFAULT_IMAGE_PATH>, using fallback path: /unknown-icon.png
→ HTTP 404 "Default image not found"I'll open a PR with the one-line fix (open(path, "rb") — plus hoisting the fallback path to a module-level constant) and three regression tests covering: default served, fallback served when default missing, 404 only when both missing.
Source: keephq/keep