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 #3900

Merged
merged 105 commits into from
Jan 16, 2025
Merged

feat!: static handler configuration #3900

merged 105 commits into from
Jan 16, 2025

Conversation

provinzkraut
Copy link
Member

@provinzkraut provinzkraut commented Dec 13, 2024

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
  • Make route handlers purely static by removing all in-place mutation

I've decided to strike the last two goals, as it would make a migration path forward needlessly complex. With the removal of the now deprecated functionality in 4.0, this will be a lot easier to achieve, and we're still in a much better place with this than before.

@github-actions github-actions bot added area/asgi area/connection area/controller area/dependencies This PR involves changes to the dependencies area/docs This PR involves changes to the documentation area/dto This PR involves changes to the DTOs area/handlers This PR involves changes to the handlers area/kwargs 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 🔨 size: large type/feat pr/internal and 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 98.27957% with 8 lines in your changes missing coverage. Please review.

Project coverage is 98.26%. Comparing base (a2afa51) to head (04c3c2a).
Report is 1 commits behind head on v3.0.

Files with missing lines Patch % Lines
litestar/handlers/base.py 95.31% 4 Missing and 2 partials ⚠️
litestar/app.py 98.66% 0 Missing and 1 partial ⚠️
...estar/handlers/websocket_handlers/route_handler.py 95.65% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             v3.0    #3900      +/-   ##
==========================================
- Coverage   98.30%   98.26%   -0.05%     
==========================================
  Files         342      342              
  Lines       15370    15350      -20     
  Branches     1694     1662      -32     
==========================================
- Hits        15109    15083      -26     
- Misses        129      133       +4     
- Partials      132      134       +2     

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

@github-actions github-actions bot added the area/docs This PR involves changes to the documentation label Jan 11, 2025
@provinzkraut provinzkraut marked this pull request as ready for review January 11, 2025 12:37
@provinzkraut provinzkraut requested review from a team as code owners January 11, 2025 12:37
Copy link
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

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

I don't have much to add other than what we've already discussed here and on discord. Great work on this.

Copy link

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

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

@provinzkraut provinzkraut merged commit d1fb342 into v3.0 Jan 16, 2025
24 of 26 checks passed
@provinzkraut provinzkraut deleted the static-handlers branch January 16, 2025 17:29
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/di area/docs This PR involves changes to the documentation 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/static-files 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.

5 participants