-
Notifications
You must be signed in to change notification settings - Fork 888
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
Break reference cycle between request and context. #3649
Conversation
LGTM, do you mind updating the changelog? |
Done. I'll also backport to 1.10. |
Backport #3649 to 1.10 branch.
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.
Minor reST syntax fix.
Co-authored-by: Steve Piercy <web@stevepiercy.com>
Anything more that needs to happen on this before merge? @stevepiercy, I made the requested rst changes. |
It's ready once @stevepiercy releases it. |
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.
Sorry, I must have missed the GitHub notification of a pushed commit.
When implementing traversal, it's common (at least for me) to store the request in the resource objects so you can do things like database lookups.
I realized this morning that this will cause a reference cycle between
request.context
andcontext.request
. Not the end of the world, obviously, but unnecessary pressure on the GC.Maybe this is the user's responsibility? We could document not to store the request in the context, or to use a WeakRef.
The framework can also prevent this by breaking the cycle once the request has been processed, which is what this PR does. Really it's just a single line (
request.__dict__.pop('context', None)
), but it got a bit more complicated than that because several router tests rely on the context object being in the request.