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

Incompatible with httpcore 0.12.0 #1495

Merged
merged 1 commit into from
Mar 3, 2021
Merged

Conversation

Simon-Le
Copy link
Contributor

@Simon-Le Simon-Le commented Mar 3, 2021

The version 0.12.0 of httpcore is not compatible. When this version is installed, all the tests using httpx.Client() will fail with the following error

AttributeError: 'Client' object has no attribute '_transport'

@florimondmanca
Copy link
Member

florimondmanca commented Mar 3, 2021

Hey 👋

Indeed, I'm also getting an error about retries which was only added in 0.12.1:

$ pip install httpx httpcore==0.12.0
$ python
>>> import httpx
>>> client = httpx.Client()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/florimond.manca/.pyenv/versions/3.8.5/lib/python3.8/site-packages/httpx/_client.py", line 605, in __init__
    self._transport = self._init_transport(
  File "/Users/florimond.manca/.pyenv/versions/3.8.5/lib/python3.8/site-packages/httpx/_client.py", line 652, in _init_transport
    return HTTPTransport(
  File "/Users/florimond.manca/.pyenv/versions/3.8.5/lib/python3.8/site-packages/httpx/_transports/default.py", line 58, in __init__
    self._pool = httpcore.SyncConnectionPool(
TypeError: __init__() got an unexpected keyword argument 'retries'

And then exiting the interpreter shows the exception you're mentioning that comes from Client.__del__:

Exception ignored in: <function Client.__del__ at 0x1013363a0>
Traceback (most recent call last):
  File "/Users/florimond.manca/.pyenv/versions/3.8.5/lib/python3.8/site-packages/httpx/_client.py", line 1134, in __del__
    self.close()
  File "/Users/florimond.manca/.pyenv/versions/3.8.5/lib/python3.8/site-packages/httpx/_client.py", line 1106, in close
    self._transport.close()
AttributeError: 'Client' object has no attribute '_transport'

The reason is that self._transport = ... was aborted mid-way, so the Client object that's still in memory doesn't have a _transport attribute yet, but __del__ assumes so.

Upgrading to httpcore==0.12.1 fixes it, yes. :-)

Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

Thanks!

@florimondmanca florimondmanca merged commit c09e61d into encode:master Mar 3, 2021
@johtso
Copy link
Contributor

johtso commented Mar 5, 2021

Argh, awkward. Is there any reasonable way to catch this kind of thing in tests? Testing with every combination of dependency versions specified in setup.py probably isn't viable. Maybe there's something simple we could do that would catch the majority of slip ups though? Maybe just test with the oldest and the newest version of httpcore allowed?

@florimondmanca
Copy link
Member

Testing against the oldest HTTPCore version as per the HTTPX requirement sounds sensible.

I'm not sure about running this as part of every CI run, but maybe we could start with that. Only putting it as a task in the release job would mean we only catch these issues once the release is ready, ideally that would be before.

Another option is to actually work locally with the lowest HTTPCore possible. That would mean pinning HTTPCore strictly in our requirements.txt, such that any API changes done separately are caught because we'd need to bump that version to continue working on HTTPX. Then we could have a simple test in the test suite to verify that this number is effectively the lowest possible number for the range specified in setup.py. I think I'd prefer this approach. Thoughts?

@tomchristie tomchristie mentioned this pull request Mar 12, 2021
This was referenced Mar 15, 2021
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.

3 participants