﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31102	Bug: Saving on a ModelAdmin with TabularInlines sometimes duplicates rows	alex zhang	nobody	"
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! :) "	Bug	closed	Uncategorized	1.11	Normal	needsinfo	admin, duplicate, tabularinline		Unreviewed	0	0	0	0	0	0
