Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10287 closed (fixed)

Formset documentation has no information about practical formset validation

Reported by: aidan Owned by: andrewbadr
Component: Documentation Version: 1.0
Severity: Keywords: docs, formsets
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Although the clean method is demonstrated, no actual validation is demonstrated.

It is unclear whether self.forms should be iterated and cleaned_data examined - a property which may or may not exist.

Attachments (1)

formset-docs.diff (3.3 KB) - added by andrewbadr 5 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by jacob

  • Owner changed from nobody to jacob
  • Status changed from new to assigned

comment:3 Changed 5 years ago by andrewbadr

  • Owner changed from jacob to andrewbadr
  • Status changed from assigned to new

Changed 5 years ago by andrewbadr

comment:4 Changed 5 years ago by andrewbadr

  • Has patch set

This patch adds a more realistic example to the formset-level clean method. It also expands the first example in the "Formset validation" section so that it matches the later example, and to better explain the contents of formset.errors.

Like several methods in the internal formset code, the example clean in this patch iterates only through the first self.total_form_count() entries in self.forms. This seems to be safer than iterating self.forms directly, because we may not use all the initial forms, or we may try to use more than max_num. If I'm wrong about this, the example clean should be changed to simply iterate through self.forms directly. That's what some other methods do, and I'm not confident that I understand the difference.

Also, my clean method accesses the forms' cleaned_data manually instead of using the formset's self.cleaned_data. This is mainly because of a comment on self.cleaned_data saying "Maybe this should just go away?", but also because self.cleaned_data iterates through self.forms, which I'm confused about (see above). If this is changed, the guard checking any(self.errors) must be kept, or else users accessing self.cleaned_data with form-level validation errors will get an uncaught exception.

comment:5 Changed 5 years ago by andrewbadr

Also, this is my first documentation patch. Did my changes overstep the bounds of the ticket by too much? I'm worried that the first validation example is now a little clunky. Critique is welcome.

comment:6 Changed 5 years ago by russellm

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

(In 11234] Fixed #10287 -- Added better examples in the docs of formset validation. Thanks to Andrew Badr for the text.

comment:7 Changed 5 years ago by russellm

(In [11241]) [1.0.X] Fixed #10287 -- Added better examples in the docs of formset validation. Thanks to Andrew Badr for the text.

Merge of r11234 from trunk.

comment:8 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.