[Django] #31932: unique_together with a formset prompt a wrong validation

37 views
Skip to first unread message

Django

unread,
Aug 22, 2020, 8:04:02 AM8/22/20
to django-...@googlegroups.com
#31932: unique_together with a formset prompt a wrong validation
-------------------------------------+-------------------------------------
Reporter: taifu | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Keywords: formset, inline,
Triage Stage: | unique_together
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Validation of a formset with a unique_together doesn't take deleted
children into account.

Method is_valid of forms/formset.py::BaseFormSet should take in account
deleted children forms to prevent a wrong validation error.


{{{
#!div style="font-size: 80%"
Simple models.py:
{{{#!python
from django.db import models
from django.utils.translation import ugettext as _


class Book(models.Model):
title = models.CharField(max_length=64, verbose_name=_("Title"))


class Language(models.Model):
language = models.CharField(max_length=64, verbose_name=_("Language"))


class Translator(models.Model):
name = models.CharField(max_length=64, verbose_name=_("Name"))
book = models.ForeignKey(Book, on_delete=models.CASCADE)
language = models.ForeignKey(Language, on_delete=models.CASCADE)

class Meta:
unique_together = ('book', 'language')
}}}
}}}

{{{
#!div style="font-size: 80%"
Simple admin.py:
{{{#!python
from django.contrib import admin

from .models import Book, Language, Translator


class TranslatorInline(admin.TabularInline):
model = Translator


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
inlines = [TranslatorInline]


@admin.register(Language)
class LanguageAdmin(admin.ModelAdmin):
pass
}}}
}}}

Wrong validation error:
[[Image(unique-together-formset.png)]]

--
Ticket URL: <https://code.djangoproject.com/ticket/31932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 22, 2020, 8:04:10 AM8/22/20
to django-...@googlegroups.com
#31932: unique_together with a formset prompt a wrong validation
-------------------------------------+-------------------------------------
Reporter: taifu | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Resolution:

Keywords: formset, inline, | Triage Stage:
unique_together | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by taifu):

* Attachment "unique-together-formset.png" added.

Django

unread,
Aug 22, 2020, 8:11:10 AM8/22/20
to django-...@googlegroups.com
#31932: unique_together with a formset prompts a wrong validation

-------------------------------------+-------------------------------------
Reporter: taifu | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Resolution:

Keywords: formset, inline, | Triage Stage:
unique_together | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:1>

Django

unread,
Aug 23, 2020, 3:46:00 PM8/23/20
to django-...@googlegroups.com
#31932: unique_together with a formset prompts a wrong validation
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner:
| anujpandey785
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:

Keywords: formset, inline, | Triage Stage:
unique_together | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anujpandey785):

* owner: nobody => anujpandey785
* status: new => assigned


Comment:

i would like to work on this.

--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:2>

Django

unread,
Aug 23, 2020, 4:35:19 PM8/23/20
to django-...@googlegroups.com
#31932: unique_together with a formset prompts a wrong validation
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: (none)

Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Resolution:

Keywords: formset, inline, | Triage Stage:
unique_together | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anujpandey785):

* owner: anujpandey785 => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:3>

Django

unread,
Aug 24, 2020, 4:51:55 AM8/24/20
to django-...@googlegroups.com
#31932: Unique checking in formsets should exclude forms marked for deletion.

-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: (none)
Type: New feature | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: formset, inline, | Triage Stage: Accepted
unique_together |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* type: Bug => New feature
* stage: Unreviewed => Accepted


Comment:

Thanks for this ticket, this looks simpler then swapping unique values
(#25139) but it's also tricky because unique checking exists at the
database level. Tentatively accepted. Would you like to work on PoC?

--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:4>

Django

unread,
Dec 15, 2020, 9:11:18 AM12/15/20
to django-...@googlegroups.com
#31932: Unique checking in formsets should exclude forms marked for deletion.
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: Aditya
| parashar
Type: New feature | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: formset, inline, | Triage Stage: Accepted
unique_together |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Aditya parashar):

* owner: (none) => Aditya parashar


* status: new => assigned


Comment:

I think the solution may be use a clean method

--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:5>

Django

unread,
Mar 21, 2023, 5:25:20 AM3/21/23
to django-...@googlegroups.com
#31932: Unique checking in formsets should exclude forms marked for deletion.
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: (none)
Type: New feature | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: formset, inline, | Triage Stage: Accepted
unique_together |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: Aditya parashar => (none)


* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:6>

Django

unread,
Jan 23, 2024, 4:33:34 AM1/23/24
to django-...@googlegroups.com
#31932: Unique checking in formsets should exclude forms marked for deletion.
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: waheedsys

Type: New feature | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: formset, inline, | Triage Stage: Accepted
unique_together |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by waheedsys):

* owner: (none) => waheedsys


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:7>

Django

unread,
Feb 8, 2024, 8:41:25 AM2/8/24
to django-...@googlegroups.com
#31932: Unique checking in formsets should exclude forms marked for deletion.
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: syed
| waheed

Type: New feature | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: formset, inline, | Triage Stage: Accepted
unique_together |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by syed waheed):

PR - https://github.com/django/django/pull/17822
--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:8>

Django

unread,
Feb 14, 2025, 8:54:29 AM2/14/25
to django-...@googlegroups.com
#31932: Unique checking in formsets should exclude forms marked for deletion.
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: syed
| waheed
Type: New feature | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: formset, inline, | Triage Stage: Accepted
unique_together |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:9>

Django

unread,
Feb 14, 2025, 9:01:48 AM2/14/25
to django-...@googlegroups.com
#31932: Unique checking in formsets should exclude forms marked for deletion.
-------------------------------------+-------------------------------------
Reporter: Marco Beri | Owner: syed
| waheed
Type: New feature | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: formset, inline, | Triage Stage: Accepted
unique_together |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/31932#comment:10>
Reply all
Reply to author
Forward
0 new messages