Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions formtools/wizard/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ManagementForm(forms.Form):
template_name = "django/forms/p.html" # Remove when Django 5.0 is minimal version.
current_step = forms.CharField(widget=forms.HiddenInput)

def __init__(self, steps, **kwargs):
self.steps = steps
super().__init__(**kwargs)
def __init__(self, *args, **kwargs):
self.steps = kwargs.pop("steps", None)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
super().__init__(*args, **kwargs)

def clean_current_step(self):
value = self.cleaned_data["current_step"]
Expand Down