-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC/1684 Context objects #2063
RFC/1684 Context objects #2063
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2063 +/- ##
=============================================
+ Coverage 92.199% 92.217% +0.018%
=============================================
Files 38 38
Lines 3461 3482 +21
Branches 581 583 +2
=============================================
+ Hits 3191 3211 +20
Misses 184 184
- Partials 86 87 +1
Continue to review full report at Codecov.
|
This is awesome! More interestingly would be, in some cases (I can see myself doing that at least), making |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some comments to some parts, nothing too fancy neither blocking, so I'll leave them there in case you want but approve the PR already, as this seems awesome 😎
The PR is ready, and we could potentially squeeze it in. My only concern is if there are any edge cases we are not considering where keep alive would apply, but that connection object is recreated. 🤔 Maybe we merge as "beta" feature and finalize it in 21.6? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome 😎
Resolves #1684
The proposal is to add a
request.ctx
like API to Sanic applications, blueprints, and connection objects.A common practice is to add arbitrary objects on the Sanic app instance. This introduces a
__fake_slots__
that is meant to be replaced by a real__slots__
in the future. In the meantime, we will check and raise a warning to direct the developer to usingapp.ctx
.Perhaps the more exciting introduction is
request.connection.ctx
.This object will remain alive so long as a single transport is kept open. Since the
KEEP_ALIVE
will not close a transport layer, we can leverage that to place a context object on it.A practical benefit of this might be only needing to check authentication or perform some expensive operation once for several calls.