[Django] #31102: Bug: Saving on a ModelAdmin with TabularInlines sometimes duplicates rows

8 views
Skip to first unread message

Django

unread,
Dec 18, 2019, 3:55:48 PM12/18/19
to django-...@googlegroups.com
#31102: Bug: Saving on a ModelAdmin with TabularInlines sometimes duplicates rows
-------------------------------------+-------------------------------------
Reporter: alex | Owner: nobody
zhang |
Type: Bug | Status: new
Component: | Version: 1.11
Uncategorized | Keywords: admin, duplicate,
Severity: Normal | tabularinline
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi! Wondering if anyone has seen this before and if this is a known bug?
Sadly (and I get how this makes this bug kind of difficult to interpret
for you all, sorry about that!), I can't reproduce it consistently.

If this is inappropriate for a ticket since it's not consistently
reproducible, apologies for the noise and I would super appreciate if you
reached out to me individually if you have any ideas!


== Background

We have the following models:

{{{
class Survey(models.Model):
organization = models.OneToOneField('organization.Organization',
on_delete=models.CASCADE, null=True, blank=True)


class SurveyQuestion(models.Model):
survey = models.ForeignKey('survey.Survey', on_delete=models.CASCADE)
text = models.CharField(max_length=255)
section_name = models.CharField(max_length=255)
}}}

They are being used for the following admins:

{{{
class SurveyQuestionInline(admin.TabularInline):
model = SurveyQuestion
fields = ('text', 'section_name',)
extra = 0


class SurveyAdmin(admin.ModelAdmin):
inlines = (SurveyQuestionInline,)
raw_id_fields = ('organization',)
fields = ('organization',)

def save_related(self, request, form, formsets, change):
organization_id = form.instance.organization_id
# do something with organization_id that's irrelevant to these models
super().save_related(request, form, formsets, change)
}}}


== Problem

Sometimes when saving the page for SurveyAdmin, the SurveyQuestion's will
duplicate.

== Details

These are some of my findings after trying to look into this...

* After adding some logging in `SurveyAdmin.save_related`, it looks like
SurveyQuestion's don't get duplicated until after the
`super().save_related(...)`
* Once duplication happens once, duplication will continue to happen on
subsequent saves of the admin page
* If changes to `SurveyQuestion.section_name` happen on SurveyAdmin, the
changes will only be applied on the duplicated rows, not on the original
SurveyQuestion

Thanks for taking the time to read this! :)

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

Django

unread,
Dec 19, 2019, 2:27:39 AM12/19/19
to django-...@googlegroups.com
#31102: Bug: Saving on a ModelAdmin with TabularInlines sometimes duplicates rows
-------------------------------------+-------------------------------------
Reporter: alex zhang | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution: needsinfo
Keywords: admin, duplicate, | Triage Stage:
tabularinline | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => needsinfo


Comment:

Sorry, there's really just not enough to go on here.

You must be doing something somewhere that's clearing the IDs from the
submitted row, so leading to inserts, rather than updates, but there's no
way of seeing that from what you've provided.

If you can narrow it down to a minimal project, then we can have a look.
(But in so doing I suspect you'll find your bug.)

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

Reply all
Reply to author
Forward
0 new messages