Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#14803 closed (fixed)

ModelFormMixing's handling of "success_url" is inconsistent with old generic view behaviour

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


Handling of "success_url" in ModelFormMixing seems to be inconsistent with how "get_absolute_url" is handled in views.generic.create_update.redirect()

In old generic views, the url could be a format string into which the object's fields would be interpolated. But that doesn't happed in ModelFormMixin: form_valid() just redirects to the result of get_success_url() (which doesn't do the interpolation)

This inconsistency should be dealt with by either:

  1. documenting the discrepency in here (presumably with the suggestion that the reader override the "get_success_url()" method to implement the interpolation)
  1. patching ModelFormMixin.get_success_url() to be consistent with old generic view handling and document the behaviour here

I prefer the latter, but the behaviour change could be a design decision (which I'm certainly not qualified to override :). Let me know, and I can prepare a patch.

Also, as an aside, it seems that redirecting back to the POSTed form would be a better last-resort, rather than throwing an ImproperlyConfigured error.


Attachments (1)

14803.2.diff (4.9 KB) - added by gg 5 years ago.
patch implements solution #2. Includes tests & docs

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by gg

patch implements solution #2. Includes tests & docs

comment:1 Changed 5 years ago by gg

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Ready for checkin

Patch looks good, mod some minor PEP8 stuff that can easily get cleaned up prior to commit.

As for the aside -- sounds like a good idea to me, but it needs a separate ticket, and a patch that implements a get_absolute_url() solution that defers to success_url if it is provided.

comment:3 Changed 5 years ago by russellm

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

(In [14808]) Fixed #14803 -- Corrected an inconsistency in redirection handling between old-style generic views and class-based views. Thanks to gg 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