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

Version 1.0.0 #2384

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Version 1.0.0 #2384

wants to merge 7 commits into from

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Dec 23, 2023

I've tried to be careful on the commit sequence here - each commit passes the pipeline by itself.

@encode/maintainers Does someone want to add a breaking change on Starlette before we go to 1.0.0? Please, let's focus on breaking changes, if there are features that can be added on minor, let's not bother with them here.


from typing_extensions import ParamSpec

from starlette.datastructures import State, URLPath
from starlette.middleware import Middleware, _MiddlewareClass
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.errors import ServerErrorMiddleware
from starlette.middleware.exceptions import ExceptionMiddleware
Copy link
Member

Choose a reason for hiding this comment

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

We need to remove ExceptionMiddleware from here. And maybe delete that file as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Where should we register the starlette.exception_handlers now?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I guess we need to get rid of is this part:

await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)

Copy link
Member Author

@Kludex Kludex Dec 24, 2023

Choose a reason for hiding this comment

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

Ah! Just to confirm: you mean that the ExceptionMiddleware should just register the exception_handlers in the scope, but the wrap_app_handling_exceptions should NOT be called there, only on the other places we have them (request_response and websocket_session). Correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yep!

Copy link
Member Author

Choose a reason for hiding this comment

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

I cannot come up with a solution for this, FYI.

Copy link
Member Author

Choose a reason for hiding this comment

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

@adriangb how do you want to proceed here? We talked in PyCon US a bit, but I don't recall how we left this.

This is the only blocker for 1.0.

The only thing is that I don't want to add any breaking change.

Copy link
Member

@adriangb adriangb Jul 23, 2024

Choose a reason for hiding this comment

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

If you want to do this without any breaking change we can just leave ExceptionMiddleware where it is and ignore this thread.

But conceptually I think the thing is that:

  1. After routing once we have a Request/Response exception handling can be done via a Request/Response (the current API).
  2. Outside of that (e.g. in other middleware or routing) we're in pure ASGI land. We could still let you catch HTTPException's but I think the API should essentially be an ASGI app HTTPException | int, Scope, Receive, Send or something like that. But that would be a breaking change. Otherwise I fear we're going to get bugs like "I wanted to catch the 404 HTTPException and log the request body but when I called .body() I got a StreamConsumed error".

To do that we'd have to replace ExceptionMiddleware with AppExceptionMiddleware or something like that with the new API and have two different arguments to Starlette for each type of exception handler.

Copy link
Member

Choose a reason for hiding this comment

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

Leaving the pure ASGI realm, I have a minimalistic and effective design. https://github.com/abersheeran/baize/blob/master/baize/asgi/shortcut.py#L59

Copy link
Member

Choose a reason for hiding this comment

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

Very nice :)

@tomchristie
Copy link
Member

I reckon Starlette 1.0 needs a clear resolution to #2673.

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.

Version 1.0
5 participants