Skip to content

Conversation

andrescollares
Copy link
Collaborator

@andrescollares andrescollares commented Jun 12, 2025

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.

Copy link

@JForsythe99 JForsythe99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 response

You could also just set raise_for_status in the real request to False, to save you from having to use the stub?

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.

aiohttp and raise_for_status, unexpected behaviours

2 participants