Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiohttp: fix multiple requests being replayed per request and add support for request_info on mocked responses #495

Merged
merged 4 commits into from
Dec 13, 2019

Conversation

nickdirienzo
Copy link
Contributor

This PR resolves #481 and #475, while also improving #456.

It was discovered that, for aiohttp specifically, when there were multiple requests recorded that looked the same, they would all be played. Looking into this further, it was because the URL we recording to was the original request's URL instead of the implicit request's that followed the redirects.

This led to the change you see here where we're recording the individual request-response chains (similar to that of other HTTP clients). We also change the explicit while cassette.can_play_response_for(vcr_request) to one that checks the response status codes and only performs a similar check if the code is a 3xx one.

While implementing that, I wanted to be extra sure that we had similar looking responses, so I started checking the request_info object. Originally, each of the mock responses do not have those objects available (I'm not sure if this is intended or not), so this PR also adds support for that. test_redirect was amended to include a specific check that we're returning the same request_info between the real one and the recorded one.

Speaking of tests, thanks to @vEpiphyte for writing test_double_requests, which made this issue repeatable and give me confidence that this works.

There are two concerns I have around this PR:

  1. This change breaks cassettes for aiohttp clients where redirects are performed because how we're using the cassette is fundamentally different. It feels weird to have a major bump for this, but if we're following SemVer, that may be right --- how do you all do versioning? Happy to include the version bump in this PR if that's preferred.
  2. I'm pretty skeptical of my usage of cassette.find_requests_with_most_matches (https://github.com/kevin1024/vcrpy/compare/master...nickdirienzo:issue-481?expand=1#diff-4636a4db24aa9f9206350b6a8e171ae1R104). While the request should exist, it may not and then the assumed look up will fail hard. We do need to get the recorded request in this block, otherwise we can't have the correct request_info. Do y'all have ideas on how to do this more safely?

Some references that I needed along the way:

@nickdirienzo
Copy link
Contributor Author

What do you think @neozenith? How can I help make this easy for you and the other maintainers to get this over the finish line? Anyone else I should tag? :)

@codecov-io
Copy link

codecov-io commented Dec 1, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@ffd2142). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #495   +/-   ##
========================================
  Coverage          ?   89.3%           
========================================
  Files             ?      24           
  Lines             ?    1562           
  Branches          ?     217           
========================================
  Hits              ?    1395           
  Misses            ?     137           
  Partials          ?      30
Impacted Files Coverage Δ
vcr/stubs/aiohttp_stubs/__init__.py 99.02% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ffd2142...c8f1744. Read the comment docs.

@neozenith
Copy link
Collaborator

Hey @nickdirienzo thank you so much for diving into this issue!

It'd make me very happy to get this over the line. If it is a breaking change though, we should bump it to v3.x.x

That said we are due to cull python2 support with PR #443 as well.

I might add this to the v3.0.x milestone https://github.com/kevin1024/vcrpy/milestone/4

I'll have to circle back to reviewing this later this week as I have limited bandwidth.

@neozenith neozenith added this to the v3.0.x milestone Dec 3, 2019
@neozenith neozenith added aiohttp issues related to aiohttp library need review labels Dec 3, 2019
@nickdirienzo
Copy link
Contributor Author

)You're welcome!

Bumping to 3.x.x sounds right. I'm mostly worried about users that may have been following redirects in their tests so they would have to re-record those tests. However, I'm not entirely sure those tests are correct with the current implementation, so maybe I'm over-worrying about this.

What's the timeline for the v3 release? (A bit of an aside: I can try to also find time to hack on #463. However, I'm not sure if that's a must-have for the release or not.)

And no worries. Take your time on reviewing this one. Appreciate any and all feedback!

@neozenith
Copy link
Collaborator

neozenith commented Dec 4, 2019

I'll aim to get on top of the review in the next week. We've been holding off the cull of python2 but that clock is ticking ...

As soon as a PR is ready and good to go I'd rather release it than sit on our hands to collect a group of PRs together since there are so few PRs it makes no sense to wait.

Also means we will increment a few major changes pretty quickly but it all goes into the changelog.

Speaking of which, you should add a line to docs/changelog.rst if you haven't already.

@nickdirienzo
Copy link
Contributor Author

Thanks for the context! Yep, 2020 is around the corner 😅

That sounds good to me. I'll update the changelog.

@neozenith
Copy link
Collaborator

Hey @nickdirienzo, sorry... I will get to this early this week. Got busy.

@nickdirienzo
Copy link
Contributor Author

nickdirienzo commented Dec 8, 2019 via email

Copy link
Collaborator

@neozenith neozenith left a comment

Choose a reason for hiding this comment

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

Looks good. Great work!

@neozenith neozenith merged commit 9ec19dd into kevin1024:master Dec 13, 2019
@nickdirienzo
Copy link
Contributor Author

Oh sweet — thanks @neozenith! Let me know when the 3.x release is and I can retest this before we release, if that'd be helpful.

@neozenith
Copy link
Collaborator

I'm preparing a release now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aiohttp issues related to aiohttp library need review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aiohttp: replaying doesn't work with two exact requests in replay mode "once"
3 participants