Skip to content

Conversation

graingert
Copy link
Contributor

@graingert graingert commented Dec 29, 2024

Summary

If user code is raising ExceptionGroups eg from TaskGroups or otherwise, they should get ExceptionGroups raised. There could also be important notes attached.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

No docs changes needed, probably should have made an issue for this.

@graingert graingert marked this pull request as ready for review December 29, 2024 17:00
@graingert graingert requested a review from Kludex December 30, 2024 08:29
@@ -258,7 +259,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
except OSError:
raise ClientDisconnect()
else:
async with anyio.create_task_group() as task_group:
async with create_collapsing_task_group() as task_group:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we also have an issue with StreamingResponse standalone?

With my comment on the other PR I was trying to avoid the changes here. 🤔

Copy link
Contributor Author

@graingert graingert Dec 30, 2024

Choose a reason for hiding this comment

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

Yeah it's the same sort of issue, but it's wrapped in two TaskGroups before the user gets the exception. Collapsing is ok here because if wait_for_disconnect raises an exception it is always 'catastrophic' eg won't be caught

@hasB4K
Copy link

hasB4K commented Jan 22, 2025

I have encountered this issue with starlette. I would love to have this PR merged tbh :)
Amazing work

cause = exc.__cause__
sc = exc.__suppress_context__
try:
raise exc

Choose a reason for hiding this comment

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

Suggested change
raise exc
raise exc from exc.__cause__ or exc.__context__

This will prevent weird traceback repetition as in pydantic/logfire#1279 (comment) and also means that existing __context__ won't be lost from the traceback and replaced with the exception group as the context instead, although it will become __cause__ instead.

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.

4 participants