Closed luhn closed 3 years ago
LGTM, do you mind updating the changelog?
Done. I'll also backport to 1.10.
Anything more that needs to happen on this before merge?
@stevepiercy, I made the requested rst changes.
It's ready once @stevepiercy releases it.
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.