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

feat!: static handler configuration [WIP] #3900

Draft
wants to merge 73 commits into
base: v3.0
Choose a base branch
from
Draft

Conversation

provinzkraut
Copy link
Member

@provinzkraut provinzkraut commented Dec 13, 2024

Experimental branch. Very much work in progress.


Basic idea is this: Instead of mutating handlers in place, treat them as static configuration objects. Once the handler tree has been collected, reduce all the layers into a single handler by recursively merging them.

Why? The idea is that this design is much less error prone and easier to follow (e.g. a lot of things currently need to happen in a specific order, otherwise they'll break). It also supports a pattern we're using in a few places now (websocket listeners + stream), where you essentially want to replace the handler with a new one. Another benefit is that this can get rid of all the deep copying we're currently doing :)

Goals

  • "Merge" handlers instead of setting ownership layers
  • Move all routing functionality from Router to Litestar instance
  • Remove (deprecate) unnecessary resolve_ methods
  • Remove ownership layer API completely
  • Remove deepcopying of route handlers during registration
  • Extract common handler config into config objects (dataclasses), so they're easier to merge / manipulate (currently I'm here)
  • Make route handlers purely static by removing all in-place mutation

provinzkraut and others added 30 commits December 12, 2024 15:54
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
* make route handlers functional decorators
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
* Remove deprecated StaticFiles and StaticFilesConfig
* remove special casing of static files app from handlers/router
* remove outdated docs sections
* Add what's new section
* Rename tests for consistency
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
* make route handlers functional decorators
* Trigger documentation build

* Trigger documentation build

* docs: update to v3 style

* docs: move some things to litestar.dev repo, change versioning, add environment tag

* docs: update landing page

* chore: update lockfile

* chore: add AA upper constraint

* fix(docs): re-colonize

* docs: enable sphinx-togglebutton

* docs: use current year var

* deps: update deps

* fix(docs): do not link __name__ for now

* fix(docs): use correct link to page

---------

Co-authored-by: Peter Schutt <[email protected]>
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
* Remove deprecated StaticFiles and StaticFilesConfig
* remove special casing of static files app from handlers/router
* remove outdated docs sections
* Add what's new section
* Rename tests for consistency
* Trigger documentation build

* Trigger documentation build

* docs: update to v3 style

* docs: move some things to litestar.dev repo, change versioning, add environment tag

* docs: update landing page

* chore: update lockfile

* chore: add AA upper constraint

* fix(docs): re-colonize

* docs: enable sphinx-togglebutton

* docs: use current year var

* deps: update deps

* fix(docs): do not link __name__ for now

* fix(docs): use correct link to page

---------

Co-authored-by: Peter Schutt <[email protected]>
* Trigger documentation build

* Trigger documentation build

* docs: update to v3 style

* docs: move some things to litestar.dev repo, change versioning, add environment tag

* docs: update landing page

* chore: update lockfile

* chore: add AA upper constraint

* fix(docs): re-colonize

* docs: enable sphinx-togglebutton

* docs: use current year var

* deps: update deps

* fix(docs): do not link __name__ for now

* fix(docs): use correct link to page

---------

Co-authored-by: Peter Schutt <[email protected]>
* Remove deprecated StaticFiles and StaticFilesConfig
* remove special casing of static files app from handlers/router
* remove outdated docs sections
* Add what's new section
* Rename tests for consistency
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
* make route handlers functional decorators
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
* make route handlers functional decorators
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
* make route handlers functional decorators
@github-actions github-actions bot removed area/docs This PR involves changes to the documentation labels Dec 13, 2024
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 47 lines in your changes missing coverage. Please review.

Project coverage is 97.98%. Comparing base (6dd1e6e) to head (a233d05).

Files with missing lines Patch % Lines
litestar/handlers/base.py 83.65% 15 Missing and 2 partials ⚠️
litestar/app.py 90.00% 9 Missing and 1 partial ⚠️
litestar/handlers/http_handlers/base.py 90.90% 9 Missing ⚠️
litestar/_asgi/asgi_router.py 27.27% 7 Missing and 1 partial ⚠️
...estar/handlers/websocket_handlers/route_handler.py 88.46% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             v3.0    #3900      +/-   ##
==========================================
- Coverage   98.30%   97.98%   -0.32%     
==========================================
  Files         340      340              
  Lines       15209    15171      -38     
  Branches     1672     1641      -31     
==========================================
- Hits        14951    14866      -85     
- Misses        127      169      +42     
- Partials      131      136       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
8 New Code Smells (required ≤ 3)
8 New Major Issues (required ≤ 2)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/asgi area/connection area/controller area/dependencies This PR involves changes to the dependencies area/dto This PR involves changes to the DTOs area/handlers This PR involves changes to the handlers area/kwargs area/layers area/openapi This PR involves changes to the OpenAPI schema area/private-api This PR involves changes to the privatized API area/router area/testing area/types This PR involves changes to the custom types Breaking 🔨 pr/internal size: large type/feat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants