Opened 8 years ago

Closed 7 years ago

Last modified 17 months ago

#10768 closed Uncategorized (wontfix)

Allow for Admin Actions to be applied to an empty QuerySet

Reported by: andrepleblanc@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords: actions
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Currently if you perform an Admin Action without selecting any rows on the change-list, the action's method doesn't get called at all. I think there are many use cases for actions which do not require an explicit collection. for example if the items are pulled from some external source there could be an action for updating the data, or perhaps various options for exporting the entire list. in this way, an action which gets an empty queryset can be applied to either "ALL" items (which currently isn't possible if the items span more than 1 page) or can apply some generic operation which doesn't pertain to a collection of items. As far as I can tell this has no negative repercussions because any potentially destructive actions, like Delete, will simply attempt to perform their action on an empty queryset, which should do nothing at all.

I haven't created a patch, but the solution is as simple as removing 2 lines (688, 689) from admin/

Change History (7)

comment:1 Changed 8 years ago by Alex Gaynor

Resolution: wontfix
Status: newclosed

This is an intentional design decision. Actions that don't act on specific items are a fundamentally different and representing them in the same UI is bad practice. You can add links to the object-tools portion of the page to have non-item specific actions.

comment:2 Changed 8 years ago by andrepleblanc@…

at the risk of stepping on someone's toes, I'm going to push this issue just a little bit further. The decision to NOT call the method when the selection is empty seems unnecessary. Actions are there for an easy way for developers to add custom functionality to the admin, it should be up to the action itself to decide how to behave with an empty queryset, and any action that is written to work with a queryset will effectively be a no-op when given an empty queryset anyway. what if all I wanted to do was add a message stating 'Please select at least one item to perform this action on' when passed an empty queryset, I dont even have that option because the admin app arbitrarily decides not to call my function, even though it can't have any negative side-effects to simply pass it an empty one. object tools may be the more 'correct' place for a developer to add these types of functionality, but realistically, it's a LOT more work, urls and views need to be constructed to handle it all, templates need to be overridden, and it just feels hacky.

comment:3 Changed 8 years ago by kvanque

Resolution: wontfix
Status: closedreopened
Triage Stage: UnreviewedDesign decision needed

i agree with andrepleblanc on this. Django is great because it allows the developer to override and
modify the framework easily. I do see Alex's argumentation as violating that pattern, why shall
django lock the developers freedom into what the django-team considers "good UI practice" ?

And as Andre has andrepleblanc has pointed out, also adding helpfull messages is restricted by this code.

comment:4 Changed 7 years ago by Chris Beaven

See also: #10768

comment:5 Changed 7 years ago by Chris Beaven

Uh, sorry. See also: #12281

comment:6 Changed 7 years ago by Karen Tracey

Resolution: wontfix
Status: reopenedclosed

Performing an action on an empty query set should do nothing. Therefore there is no point in calling the action with an empty query set. (If the action did something other than nothing, that would be surprising; enabling such surprises in the admin UI seems like a Bad Idea.) #12281 covers the case of issuing a message that something needs to be selecting before you can successfully perform an action. We should fix #12281 and reject this one.

comment:7 Changed 17 months ago by xtrinch

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

I've got promo codes in my admin panel, and it would be really nice if I could allow users to generate them with a script when they run out of them...

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