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

fix: session object was never used in aiohttp request (#700) #701

Merged
merged 5 commits into from
Jun 3, 2021

Conversation

greshilov
Copy link
Contributor

Fix for #700

@greshilov greshilov requested a review from a team as a code owner February 16, 2021 15:46
@google-cla
Copy link

google-cla bot commented Feb 16, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no This human has *not* signed the Contributor License Agreement. label Feb 16, 2021
@greshilov
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Feb 16, 2021
@arithmetic1728 arithmetic1728 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 6, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 6, 2021
# TODO: Use auto_decompress property for aiohttp 3.7+
if session is not None and session._auto_decompress:
raise ValueError(
"Client sessions with auto_decompress=True are not supported."
Copy link
Contributor

Choose a reason for hiding this comment

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

why raise the error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modifying the session object provided by the user is inappropriate in this place, so we can't disable auto_decompress ourselves. Remaining options are:

  • Ignore the session object provided by the user and leave the self.session = None. Log error in console.
  • Raise the error to stop execution and warn user, that's something went wrong with one's session.

I chose the latter option because it's better to fail early in my opinion. A user may not notice that one's session object is ignored.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I meant why auto_decompress=True are not supported. I am not familiar with aiohttp.

I think in this PR you also need to pass auto_decompress=False to https://github.com/googleapis/google-auth-library-python/blob/master/system_tests/system_tests_async/conftest.py#L29 to make the system test work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I meant why auto_decompress=True are not supported. I am not familiar with aiohttp.

I think in this PR you also need to pass auto_decompress=False to https://github.com/googleapis/google-auth-library-python/blob/master/system_tests/system_tests_async/conftest.py#L29 to make the system test work.

Ah, auto_decompress=True is supported by aiohttp, but this library prefers to do decompression on its own:

async def content(self):
# Load raw_content if necessary
await self.raw_content()
if self._is_compressed():
decoder = urllib3.response.MultiDecoder(
self._response.headers["Content-Encoding"]
)
decompressed = decoder.decompress(self._raw_content)
return decompressed

I've made required changes in conftest.py.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see. Thank you! The system test is still failing. I will take a look at why it failed.

@arithmetic1728 arithmetic1728 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 7, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 7, 2021
@greshilov
Copy link
Contributor Author

@arithmetic1728 I hope I found the problem. ASYNC_REQUESTS_SESSION is created outside the pytest-asyncio context and thus assigned to the wrong event loop.

ASYNC_REQUESTS_SESSION = aiohttp.ClientSession(auto_decompress=False)

I moved the session creation process to a separate fixture. Hope it helps.

@arithmetic1728 arithmetic1728 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 3, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 3, 2021
@arithmetic1728
Copy link
Contributor

@greshilov Great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants