fix: dump recorder output when decorated call raises - #808
Open
deepakganesh78 wants to merge 1 commit into
Open
Conversation
Always attempt the recorder dump before the context resets its registry. Preserve the decorated function's exception when a secondary dump failure occurs, while logging that failure for diagnostics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
markstory
reviewed
Jul 27, 2026
Comment on lines
+186
to
+188
| @custom_recorder.record(file_path=self.out_file) | ||
| def run(): | ||
| return None |
Member
There was a problem hiding this comment.
Shouldn't success include a captured request?
| function_raised = False | ||
| try: | ||
| return function(*args, **kwargs) | ||
| except BaseException: |
Member
There was a problem hiding this comment.
Why use BaseException? Should dump files be written to if there are syntax errors?
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.
What type of PR is this? (check all applicable)
Description
The recorder decorator previously dumped captured responses only after the decorated function returned successfully. If the function raised, control left the
with selfblock beforedump_to_file()ran, and the context manager reset the registry, losing the recording.Move the dump into the wrapper's
finallypath so responses captured before an exception are persisted. If both the decorated function and the dump fail, log the dump failure and preserve the original function exception. A dump failure still propagates normally when the decorated function succeeds.Related Issues
Fixes #705
PR checklist
CHANGESAdded/updated tests?
Regression coverage verifies:
Validation
python -m pytest . --asyncio-mode=auto --cov-report term-missing --cov responses -q— 232 passedpython -m pytest responses/tests/test_recorder.py -q— 10 passedpython -m tox -e mypy— both mypy passes succeededpython -m pre_commit run --all-files— all hooks passedresponses/_recorder.py— 100% coverage