Skip to content

[FIX] api_log: log exceptions whose headers are None - #666

Merged
OCA-git-bot merged 1 commit into
OCA:17.0from
jaenbox:17.0-fix-api_log-exception-headers
Oct 23, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:17.0from
jaenbox:17.0-fix-api_log-exception-headers

Conversation

@jaenbox

@jaenbox jaenbox commented Oct 19, 2026

Copy link
Copy Markdown

_prepare_log_exception only initializes the headers when the exception has no headers attribute. Starlette/FastAPI HTTPException always have it, but it is None when raised
without headers (404, 422...), so _inject_log_entry fails with:

  TypeError: 'NoneType' object does not support item assignment

With fastapi_log enabled on an endpoint, every error response logs a warning with its traceback and the api.log record is left without its stack trace.

The check now also covers headers set to None. Since the headers are set on the exception, fastapi_log._prepare_log_exception (which reads exception.headers for Starlette
exceptions) works too.

Added test_log_exception_none_headers: it fails with the TypeError above without the fix.

18.0 has the same issue: getattr(exception, "headers", {}) returns None when the attribute exists.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @paradoxxxzero,
some modules you are maintaining are being modified, check this out!

@lmignon

lmignon commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 17.0-ocabot-merge-pr-666-by-lmignon-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit dbaed80 into OCA:17.0 Oct 23, 2026
8 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 7e4e97a. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants