fix(aiohttp): Record error responses when raise_for_status is used#925
Open
andrescollares wants to merge 3 commits into
Open
Conversation
JForsythe99
approved these changes
Jul 20, 2025
JForsythe99
left a comment
There was a problem hiding this comment.
Was in the process of writing a fix for this issue myself but just saw that you've already submitted this PR. Looks good to me - I've made a minor refactoring suggestion on your aiohttp stubs code but am happy with your change :)
|
|
||
| await _raise_for_status(self, raise_for_status, response) | ||
|
|
||
| return response |
There was a problem hiding this comment.
nit - was thinking it might be cleaner to rewrite lines 295-318 as follows, so that you don't have to repeat the _raise_for_status call?
if cassette.can_play_response_for(vcr_request):
log.info(f"Playing response for {vcr_request} from cassette")
response = play_responses(cassette, vcr_request, kwargs)
for redirect in response.history:
self._cookie_jar.update_cookies(redirect.cookies, redirect.url)
self._cookie_jar.update_cookies(response.cookies, response.url)
else:
if cassette.write_protected and cassette.filter_request(vcr_request):
raise CannotOverwriteExistingCassetteException(cassette=cassette, failed_request=vcr_request)
log.info("%s not in cassette, sending to real server", vcr_request)
response = await real_request(self, method, url, **kwargs, raise_for_status=False)
await record_responses(cassette, vcr_request, response)
await _raise_for_status(self, raise_for_status, response)
return responseYou could also just set raise_for_status in the real request to False, to save you from having to use the stub?
ea80ee9 to
a3b94d8
Compare
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.
Fixes #635
Could be a breaking change for those that are using vcrpy with aiohttp and are expecting the library to not record error responses.