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

Handle JSON response being None #365

Merged
merged 4 commits into from
Nov 7, 2022

Conversation

JLLeitschuh
Copy link
Contributor

I just hit this strange case. Not sure what the server returned, but it certainly wasn't JSON. It may have been an empty response body.

However, "errors" not in result attempts to use result as an iterable, which fails when it is of type None with an unexpected error. This fix should make the error more intelligent.

  File "/Users/jonathanleitschuh/code/personal/security-research/moderne-campaign/venv/lib/python3.8/site-packages/gql/client.py", line 388, in execute
    data = loop.run_until_complete(
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/Users/jonathanleitschuh/code/personal/security-research/moderne-campaign/venv/lib/python3.8/site-packages/gql/client.py", line 285, in execute_async
    return await session.execute(
  File "/Users/jonathanleitschuh/code/personal/security-research/moderne-campaign/venv/lib/python3.8/site-packages/gql/client.py", line 1220, in execute
    result = await self._execute(
  File "/Users/jonathanleitschuh/code/personal/security-research/moderne-campaign/venv/lib/python3.8/site-packages/gql/client.py", line 1126, in _execute
    result = await asyncio.wait_for(
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/tasks.py", line 494, in wait_for
    return fut.result()
  File "/Users/jonathanleitschuh/code/personal/security-research/moderne-campaign/venv/lib/python3.8/site-packages/gql/transport/aiohttp.py", line 325, in execute
    if "errors" not in result and "data" not in result:
TypeError: argument of type 'NoneType' is not iterable

@codecov
Copy link

codecov bot commented Oct 3, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (0336607) compared to base (5e47f5f).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #365   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines         2215      2217    +2     
=========================================
+ Hits          2215      2217    +2     
Impacted Files Coverage Δ
gql/transport/aiohttp.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@leszekhanusz
Copy link
Collaborator

Thanks for this PR and sorry for the delay.
Could you please fix the linting issue (running make check should do the trick) and also provide a test to fix the code coverage?

@JLLeitschuh
Copy link
Contributor Author

What's the best way to test this? I'm just a user that encountered this issue, I don't have a huge amount of familiarity with testing python unfortunately.

@leszekhanusz leszekhanusz merged commit 3d85d64 into graphql-python:master Nov 7, 2022
@leszekhanusz
Copy link
Collaborator

I just hit this strange case. Not sure what the server returned, but it certainly wasn't JSON. It may have been an empty response body.

Yes, an empty json response triggers this bug.

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.

None yet

2 participants