#23656 closed Cleanup/optimization (fixed)
FormMixin.get_form's form_class argument should be optional
Reported by: | Simon Charette | Owned by: | nobody |
---|---|---|---|
Component: | Generic views | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Just like we do with SingleObjectMixin.get_object(queryset=None)
that defaults on get_queryset()
we should make FormMixin.get_form(form_class)
default on get_form_class
to make overriding easier.
The provided patch introduces a backward compatibility issue for users that overrided get_form()
on a ProcessFormView
subclass and expected form_class
to be not None
. It could be addressed by removing the changes in ProcessFormView.get()
and ProcessFormView.post()
.
Change History (9)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:2 by , 10 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
comment:3 by , 10 years ago
Patch needs improvement: | set |
---|
Okay, marking as "patch needs improvement" in the meantime so this doesn't appear in the review queue.
comment:4 by , 10 years ago
Patch needs improvement: | unset |
---|
I think I came up with a decent solution.
If someone overrides get_form
without defining a default value for form_class
a deprecation warning is raised and the unbound method is wrapped in order to make sure form_class
defaults to get_form_class()
if not provided.
I updated the PR with the POC. I guess we should we also mention this change in the deprecated section of the release notes?
comment:6 by , 10 years ago
Added the missing deprecation note and a mention in the deprecation timeline.
comment:7 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I'll move it to Accepted until I either get a consensus on the mailing list about the backward compatibility issues or I find time to avoid breaking the following case: