Ensure we don't infinitely recurse while saving CounterFields
Review Request #9843 — Created March 28, 2018 and submitted
If a model (1) defines a
CounterFieldand (2) inherits from an
abstract model that defines a
CounterField, then the magic that
CounterFielddoes to replace
_do_updateon the model instance won't
work. It will call the equivalent of
super(type(model), model)._do_update, which, due to MRO, will resolve
to the method on the abstract model. However, that method has been
CounterFieldand it will have the same behaviour. Calling
super()this way only ever can take one step up the MRO chain (since
type(model)will never be the base class) and we therefore end up in a
loop of calling
CounterField._do_updateinfinitely, which will blow
We now reach directly to
Model._do_update, avoiding the issues with
the MRO chain entirely, which results in the models being saved
A unit test has been added (which, with this patch not applied, blows
the stack) to keep track of this edge case.
Ran unit tests.
Ran unit tests on /r/9609/ without blowing the stack.