Opened 13 years ago

Closed 4 years ago

Last modified 4 years ago

#15742 closed Cleanup/optimization (fixed)

Bug: Mark all does not contain full queryset when using intermidiate pages in Django admin

Reported by: Herman S <herman.schistad@…> Owned by: Daniel
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Let's say you implement some intermidiate page for your actions in django admin, as described in the docs here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#actions-that-provide-intermediate-pages

When you call the {{ queryset }} in the intermediate page, it is all good. But let's say you have a "confirm this action" page, and when you actually call the queryset again - then the problem occurs.
It only happens when you choose more than the 100 objects on the first page and select all object with the "select all" javascript button. The action is only applied to the objects on the first page.

In order to replicate this bug:

  1. Create 100++ objects of some type
  2. Create an intermediate page which is called at some action.
  3. Choose ALL objects with first pressing the top selectbox, now the "choose all" button should appear and press this. Apply the action.
  4. Confirm it at the intermediate page.
  5. Observe that the action is only applied to the objects at the first page.

I found this article to explain the admin intermediate page actions very good: http://www.jpichon.net/blog/2010/08/django-admin-actions-and-intermediate-pages/

Change History (11)

comment:1 by Karen Tracey, 13 years ago

Component: contrib.adminDocumentation
Triage Stage: UnreviewedAccepted

The problem here involves how the "queryset" is preserved from the original action handler to the code that handles POST for the intermediate page. In the referenced blog post this is done like so:

if not form:
    form = self.AddTagForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})

This code is not actually using the queryset parameter passed into the action function but rather the list of selected action checkboxes in the post data, which is only going to be the 100 checkboxes on the individual page. The action code should be using the passed queryset parameter, which does contain the full list of all items, rather than this post data. However Django's doc at the moment shows exactly this technique of using the POST data, and that should be fixed.

As noted in the referenced blog post, the doc here is a bit lacking and in general would benefit from more complete examples. Besides not working correctly for the "select all" case, the current example of stuffing all the pks into a querystring doesn't extend well to potentially thousands of items selected -- you're going to run into querystring length issues I think. at some point. It would be good if the doc here considered some workable techniques for handling the case of thousands of selected items.

comment:2 by Karen Tracey, 13 years ago

Easy pickings: unset

#16081 reported this again.

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by anonymous, 11 years ago

I found similar problem.

In admin class of some object I set list_editable attribute. Open change-list page. Make some changes. If in site's users-side some object was added between you open admin change-list page and click save button, last objects of current page in admin page will not correctly save.

I solved this problem removing
queryset=cl.result_list
in django/contrib/admin/options.py at 1184 line

comment:5 by gamesbook@…, 11 years ago

Any chance this will be fixed for 1.6 ... intermediate pages are really useful and this limits their applicability!

comment:6 by Derek Hohls, 10 years ago

Can anyone look at the Django source code and figure a fix, based on the discussions hosted at http://www.jpichon.net/blog/2010/08/django-admin-actions-and-intermediate-pages/ ?

comment:7 by Mariusz Felisiak, 4 years ago

Has patch: set
Owner: changed from nobody to Daniel
Status: newassigned
Type: BugCleanup/optimization
Version: 1.3master

comment:8 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In e651b30:

Fixed #15742 -- Fixed an example of collecting selected objects in ModelAdmin.actions docs.

The queryset argument is already filtered, and request.POST doesn't
contain all selected objects when "Select All" is used.

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 1922119:

[3.0.x] Fixed #15742 -- Fixed an example of collecting selected objects in ModelAdmin.actions docs.

The queryset argument is already filtered, and request.POST doesn't
contain all selected objects when "Select All" is used.

Backport of e651b3095c950627b1eed1527f2bb011ddad03de from master

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 7a13f06f:

[2.2.x] Fixed #15742 -- Fixed an example of collecting selected objects in ModelAdmin.actions docs.

The queryset argument is already filtered, and request.POST doesn't
contain all selected objects when "Select All" is used.

Backport of e651b3095c950627b1eed1527f2bb011ddad03de from master

Note: See TracTickets for help on using tickets.
Back to Top