Cannot use gql with httpx transport and trio
jerr0328 opened this issue ยท 3 comments
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
(
Line 1535 in a2f327f
To Reproduce
Steps to reproduce the behavior:
- 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
- Setup the transport:
transport = HTTPXAsyncTransport(url=<any_url>)
- Setup the client:
client = Client(transport=transport, fetch_schema_from_transport=False, execute_timeout=10)
- Setup a test using the
httpx_mock
fixture, e.g.httpx_mock.add_response(url=<same url as client>, method="POST", json={"data": {}})
- 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
You're right.
In the PR #455 I modified the timeout to use anyio and it should work with trio now.
Fixed in pre-release v3.5.0b9
Great, that fixed it, thank you so much for the quick fix!