Skip to content

fix: honor log fallback after correlation ID is cleared - #115

Open
Gaurang-goyal wants to merge 1 commit into
snok:mainfrom
Gaurang-goyal:bugfix/cleared-correlation-id-fallback
Open

Gaurang-goyal wants to merge 1 commit into
snok:mainfrom
Gaurang-goyal:bugfix/cleared-correlation-id-fallback

Conversation

@Gaurang-goyal

Copy link
Copy Markdown

When the correlation ID is explicitly cleared with correlation_id.set(None), CorrelationIdFilter(default_value="-") currently attaches None to the log record. ContextVar.get(default) only uses its fallback when no value has been set, so the cleanup patterns documented for SAQ and Celery bypass the configured fallback. A formatter using {correlation_id:s} then raises TypeError.

Use the configured fallback when the retrieved ID is None. Existing IDs, empty strings, truncation, and the default None behavior are preserved, and the context itself is not changed.

Adds regression coverage for cleared IDs, fallback truncation, empty-string preservation, and formatting a cleared ID with a string format specifier.

Validation (Python 3.12/macOS):

  • Three regression cases fail before the fix; all 41 tests pass afterward.
  • 95% overall coverage; 100% for the logging filter.
  • Ruff 0.15.15 lint/format checks, ty type checking, and all applicable pre-commit hooks pass.

Test dependencies were installed in an isolated environment using current versions. Two existing/dependency warnings concern the Starlette httpx test client and an asyncio marker on a synchronous test. Upstream multi-version CI has not run yet.

Use the configured default when the context explicitly contains None, as happens after worker cleanup. Preserve empty IDs and existing truncation behavior without changing the context.

Add regression tests for cleared IDs, fallback truncation, empty strings, and string-format logging.
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.91%. Comparing base (76b61b6) to head (624436d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #115      +/-   ##
==========================================
+ Coverage   94.44%   94.91%   +0.47%     
==========================================
  Files           9        9              
  Lines         270      295      +25     
==========================================
+ Hits          255      280      +25     
  Misses         15       15              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant