Uh oh!
There was an error while loading. Please reload this page.
Stream response body in ASGITransport - #3059
Conversation
Uh oh!
There was an error while loading. Please reload this page.
e249563 to
672f459Comparejhominal
commented
Jan 17, 2024
The PR was updated, with a new |
After working with the version of I have an idea in order to fix that, here is how I think it could work:
I would like your opinion on whether the idea mentioned above should be added to the current PR, or be the object of a new PR. |
lovelydinosaur
commented
Jan 23, 2024
Either would be okay with me. |
souliane
commented
Jun 6, 2024
Hi @jhominal,
Could you please confirm that your current patch will also not work with task_group.start_soon(wrap, partial(self.stream_response, send))? Do you know about some working alternatives? I have seen https://pypi.org/project/async-asgi-testclient/ and https://gist.github.com/richardhundt/17dfccb5c1e253f798999fc2b2417d7e, not sure what to think about it. Thanks. |
jhominal
commented
Jun 6, 2024
Hello @souliane I had been working on and off on this issue for a while, in short:
|
lovelydinosaur
commented
Oct 4, 2024
Yep, that's feasible. I don't really understand if that's inherent to ASGI, or particular to the interfacing a
Sure. Does it make sense to have a task group running over the lifespan of the transport? That's then well-bounded. |
zuoc1993
commented
Nov 23, 2024
Is this PR still ongoing? I encountered the same issue. |
lovelydinosaur
commented
Nov 23, 2024
@zuoc1993 It is still ongoing yep. There's possibly a discussion to be had around the Transport API, and the limitations of a |
2f771af to
ddc87bdCompare@encode/maintainers This PR is ready. I am sorry that it took so long. In the end:
|
ddc87bd to
49b936dComparejhominal
commented
Mar 19, 2025
@tomchristie @encode/maintainers Hello, I would really appreciate a review or feedback on this PR. |
49b936d to
04bd45bComparelovelydinosaur
commented
Mar 20, 2025
Hey @jhominal thanks so much for your time on this. I'm wondering if there's a way we could introduce & stress-test this without immediately directly merging? I appreciate that's a frustrating push-back, tho it'd be a route through to sharing your work without being blocked on review here? I have been looking at the limitations of the Transport API and doing some design work there, perhaps there's a fuller conversation to be had around that in due course... |
@tomchristie Thank you for this quick feedback! The frustrating thing for me was that I was not sure how to proceed to make this PR advance - in particular, it is never clear for me, when discussion about a topic that seems important to me has died off, how to advance that discussion (potentially towards a resolution that does not make me happy, but at least it is resolved). In particular, I can see that there are still lots of other issues that need work, and I am only sporadically contributing to making them advance. (And thus it would be rude of me to be too insistent in trying to get people to look at my darlings) I think that a gist or blog post alone suffer from the drawback that we would be asking users of the streaming transport to own the streaming If we are unwilling to merge this PR as-is, I would suggest the following plan:
Nota Bene: after integrating the current PR version of ASGITransport in my at-work project yesterday, I uncovered two bugs in the current PR, related to behavior when using
I had begun looking more than a year ago at implementing the |
adriangb
commented
Mar 20, 2025
I think the fundamental problem here - and in many issues in Starlette as well - is that the maintainers, including myself, are unwilling to take on the time and risk to push changes to something that works for 97% of people (made up number) when there is little to no incentive to do so. Ultimately I think we'd end up in a better place if we were willing to try to make things better for that 3%, deal with the regressions, introduce improved APIs and put old ones through deprecation cycles, etc. But that's a lot of work. So we end up with a lot of situations like this where a valuable contribution is left to rot, which is very frustrating for the contributor. That said for this change in particular:
If you are willing to help deal with any future issues that crop up from this change @jhominal I'm inclined to support moving forward with it. If we need to de-risk we could always do something like publish it as |
provinzkraut
commented
Mar 20, 2025
Just chiming in here to give some perspective on incentive, both from my point of view as a developer that uses httpx on the daily, and maintainer of a framework that relies on httpx to implement its own test client, similar to Starlette's. I agree that outside of testing, there are few use cases of this. The testing part however I think is quite relevant, as there are certain classes of things you currently cannot test with httpx-based testing clients, which covers the vast majority of the ASGI framework landscape.
Maybe @jhominal's suggestion to (at first?) merge the PR with the new transport not as a replacement, but in addition to the existing one could be a way to achieve this. Over at Litestar we'd be more than happy to switch over our httpx-based test client to this new transport (where it would replace or own workaround), and test-drive it, and of course report and collaborate on any issues that might arise. I think with a blog post or gist this wouldn't have the same impact; Of course I could just copy-paste the code, but then it'd be quick to become out of sync, hard to report issues and collaboratively work on them etc. |
its-javierjimenez
commented
Sep 26, 2025
Its been 2 years... |
jhominal
commented
Dec 28, 2025
The PR has finally been updated (sorry that it took so long)! Basically, the ASGITransport class has been restored to its pre-PR state, and all the streaming behaviour is now isolated into its own class ( I hope that this can be merged and made available to users. |
39cc572 to
bbebfb0Compare3b145a1 to
8de4e39Compare… version into separate ASGIStreamingTransport class
8de4e39 to
6a240f4Compare
Summary
As part of my job, we needed a variant of
ASGITransportthat supports streaming (as in #2186), and this is my PR to implement that.Something that I am particularly proud of is that this PR was written without having to spawn a new task, with the consequence that it avoids issues related to task groups and context variables.
Checklist
Fixes #2186