Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#14797 closed (fixed)

ModelFormMixin's get_form_class() logic broken; fails with custom get_queryset() method

Reported by: gg Owned by: gg
Component: Generic views Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In the ModelFormMixin's get_form_class(), the logic in the else clause is broken:

  • if self.model is set, it uses that instead of the queryset (whereas according to the docs "the value of SingleObjectMixin.queryset supersedes the value provided for SingleObjectMixin.model")
  • if self.model is not set, it uses self.queryset.model, ignoring the get_queryset() method

The attached patch fixes both issues

As an aside, perhaps SingleObjectMixin should have a get_model() method that encapsulates and/or shortcuts this logic? On the one hand, using get_queryset().model isn't particularly intuitive, but on the other hand having get_model() may be getting a little too fine-grained.

Attachments (1)

14797.diff (2.5 KB) - added by gg 6 years ago.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by gg

comment:1 Changed 6 years ago by gg

  • Component changed from Uncategorized to Generic views
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by adamv

Things like "settings.LOGIN_URL" perhaps ought to be marked up as ":setting:LOGIN_URL"

comment:3 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [14809]) Fixed #14797 -- Corrected the handling of get_form_class() when a custom queryset has been defined, but a model hasn't. Thanks to Gabriel Grant for the report and patch.

comment:4 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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