Opened 8 years ago

Closed 8 years ago

#26202 closed Bug (invalid)

Admin Actions: response_action action_index will never work

Reported by: Ben Cole Owned by: nobody
Component: contrib.admin Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Whilst trying to add action buttons (with name="action" and the action name as values) to the change list rows, I stumbled across the problem where despite adding a field to the changelist form called "index", submitting the form would always fail (even if selecting an action from the drop down first).

By debugging inside django.contrib.admin.options.response_action() I found there is some code that attempts to get the action from the request if it was in a list.

# Use the action whose button was pushed
try:
    data.update({'action': data.getlist('action')[action_index]})
except IndexError:
    # If we didn't get an action from the chosen form that's invalid
    # POST data, so by deleting action it'll fail the validation check
    # below. So no need to do anything here
    pass

The trouble is, data is a QueryDict whose update method (by design) adds new value to existing keys by creating or appending to a list. This then causes the later form to fail validation.

I don't see why this needs to be an update, and in fact it should just be a key reassignment.

Change History (4)

comment:1 by Tim Graham, 8 years ago

Have you tried making your proposed change and checking if any tests fail?

comment:2 by Ben Cole, 8 years ago

Yes. I've just made the change locally and run the tests and they all pass.

Just looking to write a regression test, then I'll put in a PR

comment:3 by Ben Cole, 8 years ago

This is invalid. Upon further investigation, this is how QueryDict is supposed to work. The update() call appends the value at action_index to the end of the list. The get() call later in the form's clean() process returns the last element in the list.

There is some weird issue where if I'm using PyCharm's debugger, and break before form.is_valid() is called, it will always return False even through stepping through the code shows that the POST data is processed correctly and should validate the form.

comment:4 by Tim Graham, 8 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top