Opened 9 years ago

Closed 8 years ago

#5153 closed (wontfix)

Allow "bypassing" validation in newforms

Reported by: Christopher Lenz <cmlenz@…> Owned by: nobody
Component: Forms Version: master
Severity: Keywords: feature
Cc: cgrady@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:


I'm trying to generate a preview page based on a temporary model that should be populated from a form. The idea here is to be able to reuse the same template code as is used for the real view of the model, so simply basing the preview on the raw form data won't cut it.

There are actual two problems here:

  1. There seems to be no way whatsoever to trick newforms into keeping the cleaned_data even when a validation error is encountered. It's stubbornly delete the cleaned_data attribute.
  2. newforms.models.save_instance checks whether the form has errors, so it won't allow me to populate the model instance from the form, even if commit=False.

For (1), I think there should be an option to not discard the cleaned_data on errors. For (2), there should be an option to ignore validation errors. I'm attaching a patch that does this.

Attachments (1)

ticket5153.diff (2.5 KB) - added by Christopher Lenz <cmlenz@…> 9 years ago.
Patch that adds ensure_valid option

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by Christopher Lenz <cmlenz@…>

Patch that adds ensure_valid option

comment:1 Changed 9 years ago by Christopher Lenz <cmlenz@…>

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

comment:2 Changed 8 years ago by SmileyChris

  • Needs tests set
  • Triage Stage changed from Unreviewed to Design decision needed

I'm not sure this is the best way to go about fixing your problem, but maybe I'm not really getting it. Perhaps bring this up in the Django Dev group?

comment:3 Changed 8 years ago by Collin Grady <cgrady@…>

  • Cc cgrady@… added

I don't really get it either... Why would you preview invalid data? Wouldn't you expect it to bounce back to the form until things are valid, then preview before the final save?

With that flow, this wouldn't be an issue at all, since the form would be valid and cleaned_data would remain :)

comment:4 Changed 8 years ago by PhiR

  • Keywords feature added

comment:5 Changed 8 years ago by ubernostrum

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

Preview requirements should be handled by using FormPreview; in the meantime, I'm punting this as wontfix. If there's a valid used case, bring it up on django-developers.

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