Code

#18906 closed Bug (fixed)

BaseModelFormSet.validate_unique should ignore forms marked for deletion

Reported by: c.pollock@… Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

is_valid() returns false for a formset where uniquness is violated even if one of the forms where the violation occurs has DELETE set to true in cleaned data

so maybe line 521 in django/forms/models.py which is currently

if not hasattr(form, "cleaned_data"):

continue

should read something like, so it will ignore forms that are getting deleted anyway

if not hasattr(form, "cleaned_data") or form.cleaned_data.get('DELETE', True):

continue

unless of course I have completely missed the point

Cheers
Charlie

Attachments (1)

18906-1.diff (5.4 KB) - added by claudep 22 months ago.
Do not validate deleted forms

Download all attachments as: .zip

Change History (4)

comment:1 Changed 22 months ago by claudep

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

I was able to reproduce the issue in a test.

Changed 22 months ago by claudep

Do not validate deleted forms

comment:2 Changed 22 months ago by claudep

  • Has patch set

comment:3 Changed 17 months ago by Claude Paroz <claude@…>

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

In f44922c79516b9caf0e09fb060f20c896668b90f:

Fixed #18906 -- Ignored to-be-deleted forms in formset validate_unique

Thanks c.pollock at bangor.ac.uk for the report.

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.