I raised a ticket about the dangers of FormMixin.initial
in the hopes that some of the older contributors might be able to shed some light on why it’s declared that way but it was closed as invalid so I doubt anyone will read it
(I spent a couple of days tracking down this bug caused by a junior accidentally mutating it!)
To summarise, FormMixin.initial
is a mutable class attribute:
class FormMixin:
initial = {}
I don’t need to go into why this is bad but I do want to mention if you intialise from __init__()
then the test suite still passes
My questions:
- Anyone know why it wasn’t initialised in
__init__()
to begin with? (Claude seems to be have been part of the original ticket highlighting this) - If the intention is to declare
initial
outright in subclasses or to overrideget_initial()
, then what is the point of initialising it anyway? The usual attribute-overridden-by-method pattern seems to have the attrs set toNone
anyway - Is Carlton going to respond to this with “Well some folks may be expecting this behaviour so we can’t change it” ?
I’m not going to be annoyed if it stays like this but I just want to make sure everyone’s aware of the dangerous anti-pattern hiding in the codebase ready to catch out unsuspecting junior devs.