Fix prepare_body stream detection for __getattr__-based file wrappers#7433
Conversation
|
Hi @k223kim, This PR has quite a few oddities in it, did you happen to use an LLM to generate it? There are unrelated tests and the change itself is wrong (at least for the issue you reported). |
|
Hey @nateprewitt , thanks for the review! |
|
Perhaps - I can be more precise with the if-statement and just restoring it to If this sounds better, happy to adjust test accordingly. |
|
Yep, it should be The tests are engraining a lot of tqdm/use case specific semantics into the test suite that I'm not sure we want. While this may work, I don't really want to call it a "supported pattern" because that tends to lead to other areas that didn't support this before getting PRs to "fix" support. I think it's unlikely this changes again in the future, the def test_getattr_proxy_stream_follows_redirect(self, httpbin):
"""Ensure stream wrappers that don't implement __iter__ directly are still detected."""
class AttrProxy:
def __init__(self):
self._file = io.BytesIO(b"data")
def __getattr__(self, name):
return getattr(self._file, name)
r = requests.post(httpbin("redirect-to?url=/post&status_code=307"), data=AttrProxy())
assert r.json()["data"] == "data" |
|
@nateprewitt Makes sense. Adjusted the PR 😄 Would appreciate it if you can take a look! |
nateprewitt
left a comment
There was a problem hiding this comment.
One minor tweak for readability, but otherwise this looks good. Thanks @k223kim!
Resolves #7432 .
Add
hasattr(data, "__iter__")as a fallback stream detector:This catches file-like objects that proxy their interface through
__getattr__, restoring the 2.33.1 behavior without reverting the isinstance(Iterable) modernization for standard iterables.