#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.97953057b1569581cdc88d36c1000567%40djangoproject.com.