Opened 4 years ago
Last modified 10 months ago
#31932 assigned New feature
Unique checking in formsets should exclude forms marked for deletion.
Reported by: | Marco Beri | Owned by: | syed waheed |
---|---|---|---|
Component: | Forms | Version: | 3.1 |
Severity: | Normal | Keywords: | formset, inline, unique_together |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Simple models.py:
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')
Simple admin.py:
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
Attachments (1)
Change History (9)
by , 4 years ago
Attachment: | unique-together-formset.png added |
---|
comment:1 by , 4 years ago
Summary: | unique_together with a formset prompt a wrong validation → unique_together with a formset prompts a wrong validation |
---|
comment:2 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 4 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:4 by , 4 years ago
Summary: | unique_together with a formset prompts a wrong validation → Unique checking in formsets should exclude forms marked for deletion. |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → New feature |
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?
comment:5 by , 4 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
I think the solution may be use a clean method
comment:6 by , 21 months ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:7 by , 11 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
i would like to work on this.