#25919: Wrong behavior after saving on changelist page when any field is list_editable -------------------------------+-------------------- Reporter: c0ntribut0r | Owner: nobody Type: Bug | Status: new Component: contrib.admin | Version: 1.9 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 1 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- Assume there is a simple model {{{ class SomeModel(models.Model): name = models.CharField('name', max_length=64) }}} and simple admin for it (note 2 items per page and in-line editable field "name") {{{ @admin.register(SomeModel) class SomeModelAdmin(admin.ModelAdmin): list_display = ['id' ,'name'] list_editable = ['name'] list_per_page = 2 }}} Go to admin page and create two instances of SomeModel with names, say, "alpha" and "beta". Then, open the same admin page ({{{/admin/testapp/somemodel/}}}) in another browser tab and create another instance ("gamma"). Return to the first tab (it's of course unchanged and there still remain "alpha" and "beta" instances) and change in-line field "name" from "alpha" to "lambda" and press "save". Then press "show all" and you'll see that you haven't changed "alpha" to "lambda" - you created new instance "lambda", and "alpha" also remains there!
The source of this bug is in {{{ django/contrib/admin/options.py }}}: {{{ # Handle POSTed bulk-edit data. if (request.method == "POST" and cl.list_editable and '_save' in request.POST and not action_failed): FormSet = self.get_changelist_formset(request) formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list) }}} When user clicks "save", the page sends correct POST data like this: {{{ "form-0-id" = "0", "form-0-name" = "beta", "form-1-id" = "1", "form-1-name" = "lambda" <-- was "alpha" before }}} But there is code ({{{ queryset=cl.result_list }}}) which restricts form's instances to those that are on current admin page ({{{ /admin/testapp/somemodel/ }}}). As you remember, we have 3 instances - "alpha", "beta", "gamma", and according to {{{ list_per_page = 2 }}} only last two instances are shown - these are "beta" and "gamma". When the form's POST data ("beta", "alpha -> lambda") fits instances from queryset ("beta", "gamma"), it finds "beta" and changes it without errors, but it cannot find "alpha" and change it - so it thinks that we added new record and creates an instance with value "lambda". This is not a desired behavior. Removing the queryset restriction solves this problem. I am wondering whether that queryset was there at all. -- Ticket URL: <https://code.djangoproject.com/ticket/25919> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/054.8e1ad602da4ea338080296ddfc0459eb%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.