Fix: Define kwargs properly for step validation#2
Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts ManagementForm initialization so wizard step validation can pass steps via kwargs without conflicting with normal Form positional args (e.g., POST data), as a follow-up to #1’s current_step validation work.
Changes:
- Update
ManagementForm.__init__to accept*args, **kwargsand pullstepsfrom kwargs. - Ensure
stepsis stored on the instance before callingforms.Form.__init__.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.steps = steps | ||
| super().__init__(**kwargs) | ||
| def __init__(self, *args, **kwargs): | ||
| self.steps = kwargs.pop("steps", None) |
There was a problem hiding this comment.
steps is now optional (kwargs.pop("steps", None)), but clean_current_step() assumes it’s iterable; omitting steps will raise a TypeError at validation time (value not in None). Consider making steps a required kw-only argument (e.g., def __init__(..., *, steps, **kwargs)) or raise a clear error in __init__ when steps is missing/None so failures are immediate and actionable.
| self.steps = kwargs.pop("steps", None) | |
| self.steps = kwargs.pop("steps", None) | |
| if self.steps is None: | |
| raise TypeError("ManagementForm requires a 'steps' keyword argument.") | |
| # Ensure that steps is iterable so membership checks in clean_current_step() | |
| # do not raise a TypeError at validation time. | |
| try: | |
| iter(self.steps) | |
| except TypeError as exc: | |
| raise TypeError("ManagementForm 'steps' must be an iterable of step names.") from exc |
Following #1