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

Instance of StreamingBody returns True for isinstance Iterable check #1098

Open
6 tasks done
FeeeeK opened this issue Mar 11, 2024 · 4 comments
Open
6 tasks done

Instance of StreamingBody returns True for isinstance Iterable check #1098

FeeeeK opened this issue Mar 11, 2024 · 4 comments
Labels

Comments

@FeeeeK
Copy link

FeeeeK commented Mar 11, 2024

Describe the bug
StreamingBody returns True for isinstance Iterable check when it shouldn't, this can lead to some problems, for example, wrong content encoding in httpx (link) and inability to use StreamingBody as content in httpx.AsyncClient

> isinstance(StreamingBody, Iterable)
False
> isinstance(StreamingBody, AsyncIterable)
False
> isinstance(StreamingBody(b"", 0), Iterable)
True
> isinstance(StreamingBody(b"", 0), AsyncIterable)
True
> StreamingBody(b"", 0).__iter__
<method-wrapper '__iter__' of StreamingBody object at 0x0000021D9F2B93C0>
> StreamingBody(b"", 0).__aiter__
<bound method StreamingBody.__aiter__ of <StreamingBody at 0x0000021D9FC6AC40 for bytes at 0x00007FF96586D328>>
> for _ in streaming_body: pass
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'ClientResponse' object is not iterable

Checklist

  • I have reproduced in environment where pip check passes without errors
  • I have provided pip freeze results
  • I have provided sample code or detailed way to reproduce
  • I have tried the same code in botocore to ensure this is an aiobotocore specific issue
  • I have tried similar code in aiohttp to ensure this is is an aiobotocore specific issue
  • I have checked the latest and older versions of aiobotocore/aiohttp/python to see if this is a regression / injection

pip freeze results

...
aioboto3==11.3.1
aiobotocore==2.6.0
aiohttp==3.9.3
boto3==1.28.17
botocore==1.31.17
...

Environment:

  • Python Version: 3.11.8
  • OS name and version: windows

Additional context
Add any other context about the problem here.

@jakob-keller
Copy link
Collaborator

Hello and thanks for reporting!

I believe you are correct: StreamingBody is indeed not iterable. The false positive isinstance check appears to be due to having wrapt.ObjectProxy as a parent class.

There might be several ways to deal with this issue:

  1. Make wrapt.ObjectProxy play nicely with isinstance checks by addressing the issue upstream
  2. Tweak StreamingBody to ensure isinstance check returns expected result (if possible)
  3. Drop wrapt.ObjectProxy as a parent class
  4. Leave StreamingBody as it is and work around the issue in downstream code

@thehesiod: Any thoughts?

@FeeeeK
Copy link
Author

FeeeeK commented Mar 11, 2024

Looks like this issue is already 8 years old: GrahamDumpleton/wrapt#93 so it seems to me that option 3 would most likely be the solution

@jakob-keller
Copy link
Collaborator

Looks like this issue is already 8 years old: GrahamDumpleton/wrapt#93 so it seems to me that option 3 would most likely be the solution

That's what I feared

@thehesiod
Copy link
Collaborator

thehesiod commented Mar 11, 2024 via email

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

No branches or pull requests

3 participants