catch_exception crashes when request.state.tenant_id is unset
Author: juangaltCreated Sep 28, 2026Updated Sep 28, 2026
keep/api/api.py catch_exception formats request.state.trace_id and request.state.tenant_id while handling an exception. Starlette State.__getattr__ raises AttributeError when either attribute is absent, so the handler fails and the original exception is discarded.
The same body is on v0.53.0 and current main. Fix: getattr for both attributes and logger.exception, keeping the JSON 500 shape {message, trace_id, error_msg}.
PR: https://github.com/keephq/keep/pull/6854
This is not keephq/keep#6089 or #6100; those are different tenantId surfaces.
Source: keephq/keep