aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

fix: CookieJar quote_cookie / unsafe args lost when input cookies to _request

Open exherb opened this issue 3 years ago • 14 comments

What do these changes do?

the result of those two code blocks are not the same.

import aiohttp
jar = aiohttp.CookieJar(quote_cookie=False)
async with aiohttp.ClientSession(cookie_jar=jar, cookies=cookies) as session:
  async with session.post(url) as r:
    print(await r.json())  
import aiohttp
jar = aiohttp.CookieJar(quote_cookie=False)
async with aiohttp.ClientSession(cookie_jar=jar) as session:
  async with session.post(url, cookies=cookies) as r:  # cookies value got quoted even current cookie_jar quote_cookie is False
    print(await r.json())  

Are there changes in behavior for the user?

no

Checklist

  • [x] I think the code is well written
  • [x] Unit tests for the changes exist
  • [x] Documentation reflects the changes
  • [x] If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • [x] Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

exherb avatar Apr 08 '22 11:04 exherb

This pull request introduces 1 alert when merging fc26cd7cde87caef91bb5e7c3a4ecd9507dacb6d into 747110c2230b00d74b4db7acd21ba85177c2b780 - view on LGTM.com

new alerts:

  • 1 for Unused import

lgtm-com[bot] avatar Apr 08 '22 11:04 lgtm-com[bot]

It's unclear what this PR is supposed to do, and most of the changes are unrelated. Please don't start changing a random selection of annotations, they won't be accepted.

Dreamsorcerer avatar Apr 08 '22 16:04 Dreamsorcerer

It's unclear what this PR is supposed to do, and most of the changes are unrelated. Please don't start changing a random selection of annotations, they won't be accepted.

it's changed by robot, not me. https://github.com/aio-libs/aiohttp/pull/6682/commits/fc26cd7cde87caef91bb5e7c3a4ecd9507dacb6d

exherb avatar Apr 08 '22 23:04 exherb

It's unclear what this PR is supposed to do, and most of the changes are unrelated. Please don't start changing a random selection of annotations, they won't be accepted.

it's changed by robot, not me. fc26cd7

Ah, sorry. I'll look into that, not sure why that's changed.

Dreamsorcerer avatar Apr 08 '22 23:04 Dreamsorcerer

ok, thanks. And I just updated why submit this pr.

exherb avatar Apr 08 '22 23:04 exherb

Weird that the pre-commit check is now passing without making those changes...

Dreamsorcerer avatar Apr 08 '22 23:04 Dreamsorcerer

Ah, I think you added the future import in your commit, which appears to trigger it: https://github.com/asottile/pyupgrade#pep-585-typing-rewrites

You've correctly removed that import in the new code.

Dreamsorcerer avatar Apr 09 '22 00:04 Dreamsorcerer

Codecov Report

Merging #6682 (dae5553) into master (747110c) will decrease coverage by 0.00%. The diff coverage is 71.42%.

:exclamation: Current head dae5553 differs from pull request most recent head c55f2ab. Consider uploading reports for the commit c55f2ab to get more accurate results

@@            Coverage Diff             @@
##           master    #6682      +/-   ##
==========================================
- Coverage   93.36%   93.36%   -0.01%     
==========================================
  Files         104      104              
  Lines       30628    30634       +6     
  Branches     3077     3077              
==========================================
+ Hits        28596    28601       +5     
- Misses       1859     1860       +1     
  Partials      173      173              
Flag Coverage Δ
unit 93.28% <71.42%> (-0.01%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiohttp/client.py 24.83% <0.00%> (ø)
aiohttp/cookiejar.py 98.47% <75.00%> (-0.37%) :arrow_down:
aiohttp/abc.py 100.00% <100.00%> (ø)

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 747110c...c55f2ab. Read the comment docs.

codecov[bot] avatar Apr 09 '22 00:04 codecov[bot]

Ah, I think you added the future import in your commit, which appears to trigger it: https://github.com/asottile/pyupgrade#pep-585-typing-rewrites

You've correctly removed that import in the new code.

maybe import annotation from future will make typing clear?

exherb avatar Apr 09 '22 00:04 exherb

At an initial look, it might be reasonable. It will need a new test though, ideally one that reproduces the problem described in the PR description.

Ok, I will ad some test latter

exherb avatar Apr 09 '22 00:04 exherb

maybe import annotation from future will make typing clear?

The annotations are correct for Python 3.7+, which is what we support. They will get updated as we drop support for old versions.

If we were to make those changes, then it would cause problems with anything that tried to inspect annotations at runtime.

Dreamsorcerer avatar Apr 09 '22 00:04 Dreamsorcerer

At an initial look, it might be reasonable. It will need a new test though, ideally one that reproduces the problem described in the PR description.

I found quote_cookie = False already tested, I have no idea to how to test aiohttp.Client, any suggestions?

exherb avatar Apr 12 '22 02:04 exherb

@Dreamsorcerer

exherb avatar Apr 13 '22 00:04 exherb

I think you should be able to figure it out by copying one of the tests in: https://github.com/aio-libs/aiohttp/blob/master/tests/test_client_functional.py

But, if you struggle to get hold of the cookies, you could maybe use mock.patch.object() to mock out self._request_class, and then check what cookies get passed to that function?

Dreamsorcerer avatar Apr 15 '22 13:04 Dreamsorcerer