-
-
Notifications
You must be signed in to change notification settings - Fork 999
Stream response body in ASGITransport #3059
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
base: master
Are you sure you want to change the base?
Conversation
e249563 to
672f459
Compare
|
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. |
Either would be okay with me. |
|
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. |
|
Hello @souliane I had been working on and off on this issue for a while, in short:
|
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. |
|
Is this PR still ongoing? I encountered the same issue. |
|
@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
ddc87bd
Compare
|
@encode/maintainers This PR is ready. I am sorry that it took so long. In the end:
|
ddc87bd to
49b936d
Compare
|
@tomchristie @encode/maintainers Hello, I would really appreciate a review or feedback on this PR. |
49b936d to
04bd45b
Compare
|
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 |
|
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 |
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 been 2 years... |
|
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
bbebfb0
Compare
3b145a1 to
8de4e39
Compare
… version into separate ASGIStreamingTransport class
8de4e39 to
6a240f4
Compare
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