Opened 3 hours ago
Last modified 3 hours ago
#36662 new Cleanup/optimization
django.contrib.messages Storage creates circular references with Request objects
Reported by: | Raphael Gaschignard | Owned by: | |
---|---|---|---|
Component: | contrib.messages | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Raphael Gaschignard | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
To be honest I don't know how much people care about this kind of issue, but I am having some (very silly) operational issues downstream of Requests getting garbage collected at awkward times.
Request objects hold onto message storages via Request._messages. The storage classes hold references back to Request. This creates a reference cycle preventing Requests from being collected as fast as they could be (and can create some awkwardness in CPython, with del calls happening on associated objects in seemingly unrelated spots)
The "simple" fix here would be to hold onto request in the storage through a weakref, and add a property to get the request object on the storage class.
Attachments (1)
Change History (2)
by , 3 hours ago
Attachment: | cycle.2.png added |
---|
comment:1 by , 3 hours ago
Description: | modified (diff) |
---|
An example of the sort of cycle that appears (objgraph output)