Repository navigation
fix: preserve exceptions in instrumented async context managers - #2767
Merged
alexmojaki merged 1 commit intoNov 10, 2026
Conversation
PR overviewNo security issues were found in this pull request. Reviews
|
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
@asynccontextmanagerabove@logfire.instrument(allow_generator=True), exceptions in theasync withbody stop at the instrumentation wrapper. The original manager never receives them, so rollback and exception suppression can be skipped and cleanup runs late. A local SQLite reproduction leaves a failed transaction open; the next successful commit also commits its write.Forward exceptions to the original async generator while keeping the span open during cleanup. Regression tests cover propagation, suppression, exception identity, replacement errors, cancellation, close, and ordinary iteration. The sending-values limitation remains unchanged.
Tested on the checkout:
test_logfire.pyandtest_metrics.pypass on Python 3.13 (162 passed, 1 skipped) and 3.10 (161 passed, 2 skipped); Ruff formatting/lint and changed-file Pyright pass. The public SQLite reproduction now rolls back before exit. Focusedinstrument.pyline/branch coverage is 100%; combined matrix coverage still needs CI.Full-project local Pyright lacks optional integration dependencies and reports exactly the same output on pristine base and this patch. The full integration suite wasn't run locally.
Implemented with GPT-6.1 Sol (high); the coordinator reviewed the diff and independently reran the SQLite reproduction before and after.