Fix stale state issues in RelationCounterField when deleting models.
Review Request #9231 — Created Sept. 28, 2017 and submitted
RelationCounterFieldkeeps track of each model instance that contain
references to other models, in order to bump their counter fields, and
it tries to notice when a new instance of a model has claimed the same
ID as an old one (for use in test suites). However, it only worked when
the old instances fell out of scope, and not when they were deleted
(which resets the ID to None and prevents a later lookup from
The field now tracks the
pre_deletesignal for the instance, taking
care to reset state and untrack the instance. It also clears up signal
handlers, ensuring we don't have any stale ones sitting around.
Unit tests have been added for these fixes.
Verified that the new unit tests failed before this fix, and pass
Ran the Review Board test suite (with an upcoming change), which was
failing. It now passes after this.