Skip to content

Fix traceback colors shared between logging handlers - #144

Open
nk-batman21 wants to merge 1 commit into
borntyping:mainfrom
nk-batman21:fix/exception-cache-isolation
Open

nk-batman21 wants to merge 1 commit into
borntyping:mainfrom
nk-batman21:fix/exception-cache-isolation

Conversation

@nk-batman21

Copy link
Copy Markdown

Fixes #143.

On Python 3.13+, the colored traceback is cached on the shared LogRecord. A later plain formatter reuses its ANSI escapes; running the plain formatter first prevents the colored formatter from coloring the traceback.

Keep plain exception text on the original record for record-forwarding callers, and render each formatter's exception colors on a local copy with a fresh cache. Records that arrive with cached exception text and no exc_info retain that text.

Tests cover both handler orders with standard, no_color and non-TTY formatters, plus pickled records with exception information removed. Seven new regressions fail before the fix; the two cached-text-only controls pass before and after.

Validation:

  • Full pytest suite on Python 3.8 through 3.14: 33 tests on each older version, 44 on Python 3.13 and 3.14.
  • Tox black, flake8, mypy and py environments pass.
  • Whole-project Black, Flake8 and mypy checks on Python 3.14, and git diff --check, pass.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cached exception colors leak into no_color and standard formatters

1 participant