Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 3 months ago by LunarMariner357

Why is FormMixin.initial a mutable class attribute and what purpose does it serve?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I raised a ticket about the potential pitfalls of having a mutable class attribute for FormMixin.initial and hoped that some older contributors could explain the reasoning behind it. Unfortunately, the ticket was closed as invalid, so I'm not expecting much feedback from that channel.

I spent a couple of days tracking down a bug that occurred when a junior developer accidentally mutated this attribute. To summarize, the issue is that FormMixin.initial is declared as a mutable class attribute, as shown below:

PYTHON
class FormMixin: initial = {}

I'm not here to rehash why mutable defaults are problematic, but I did notice that even if you initialize it in __init__(), the test suite still passes.

My questions are:

  • Why wasn't initial initialized inside __init__() to begin with? (Claude seems to have been involved in the original discussion on this.)
  • If the intention is to have subclasses explicitly declare initial or override get_initial(), what benefit does this initialization provide? After all, the typical pattern for an attribute overridden by a method would be to set it to None.
  • Could we expect a response like “Some folks may be expecting this behavior so we can’t change it”?

I'm not upset if this behavior remains unchanged, but I want to raise awareness of this potentially dangerous anti-pattern in the codebase to help prevent similar issues for unsuspecting junior developers.

5

Comments 0

Answers 0

Views 58

0 Answers

Discussion

No comments yet.