Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#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 Tim Graham, 10 years ago

Triage Stage: UnreviewedReady for checkin

comment:2 by Simon Charette, 9 years ago

Triage Stage: Ready for checkinAccepted

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:

class MyFormMixin(FormMixin):
    def get_form(form_class):
        return form_class(...)

comment:3 by Tim Graham, 9 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 Simon Charette, 9 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:5 by Tim Graham, 9 years ago

Yes, and of course the deprecation timeline as well.

comment:6 by Simon Charette, 9 years ago

Added the missing deprecation note and a mention in the deprecation timeline.

comment:7 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Simon Charette <charette.s@…>, 9 years ago

Resolution: fixed
Status: newclosed

In f2ddc439b1938acb6cae693bda9d8cf83a4583be:

Fixed #23656 -- Made FormMixin.get_form's form_class argument optional.

Thanks Tim Graham for the review.

comment:9 by Tim Graham <timograham@…>, 9 years ago

In 491de4f0:

Refs #23656 -- Required FormMixin.get_form() form_class parameter to be optional.

Per deprecation timeline.

Note: See TracTickets for help on using tickets.
Back to Top