Skip to content

Cannot use gql with httpx transport and trio #454

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

Closed
jerr0328 opened this issue Dec 15, 2023 · 3 comments
Closed

Cannot use gql with httpx transport and trio #454

jerr0328 opened this issue Dec 15, 2023 · 3 comments
Labels
type: feature A new feature

Comments

@jerr0328
Copy link

Describe the bug
This is 50% a bug and 50% a missing feature 😅 In #154 there was an ask for the HTTPX transport which support Trio. It was completed in #370 but if trying to actually use with AnyIO with the trio backend, there's an exception due to the use of asyncio.timeout: RuntimeError: no running event loop caused by gql/client.py:1535 (

gql/gql/client.py

Line 1535 in a2f327f

result = await asyncio.wait_for(
)

To Reproduce
Steps to reproduce the behavior:

  1. Use gql 3.5.0b8, along with httpx, anyio[trio], and setup pytest to run the test with anyio backends (asyncio and trio by default). Use pytest-httpx to mock out actual HTTP calls though not strictly necessary
  2. Setup the transport: transport = HTTPXAsyncTransport(url=<any_url>)
  3. Setup the client: client = Client(transport=transport, fetch_schema_from_transport=False, execute_timeout=10)
  4. Setup a test using the httpx_mock fixture, e.g. httpx_mock.add_response(url=<same url as client>, method="POST", json={"data": {}})
  5. Do the actual request: await client.execute_async(query, variable_values=variable_values) (query and variable_values can be anything, it doesn't matter at this point)

Expected behavior
I would expect that if I'm using httpx transport, that the AsyncClient would be using AnyIO for timeouts working with any backends supported by httpx. Alternatively, the async client should not be handling timeouts on its own and that should be up to the transport (httpx can handle the timeout, for instance). The end result would still be that I could run gql in trio using the httpx transport without any issues

System info (please complete the following information):

  • OS: macos 14.2
  • Python version: 3.12.1
  • gql version: 3.5.0b8
  • graphql-core version: 3.3.0a3
@leszekhanusz
Copy link
Collaborator

You're right.
In the PR #455 I modified the timeout to use anyio and it should work with trio now.

@leszekhanusz
Copy link
Collaborator

Fixed in pre-release v3.5.0b9

@jerr0328
Copy link
Author

Great, that fixed it, thank you so much for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants