Code

Opened 5 years ago

Closed 4 years ago

#10768 closed (wontfix)

Allow for Admin Actions to be applied to an empty QuerySet

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

Description

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/options.py

Attachments (0)

Change History (6)

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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 5 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 5 years ago by kvanque

  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Design 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 4 years ago by SmileyChris

See also: #10768

comment:5 Changed 4 years ago by SmileyChris

Uh, sorry. See also: #12281

comment:6 Changed 4 years ago by kmtracey

  • Resolution set to wontfix
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.