table actions with preempt = True get called twice

Asked by Eric Peterson

Is there a good way to avoid this from happening???

It looks like the table actions with preempt=True get called twice, once during the maybe_preempt and the other time with normal action handling. It seems like the normal action handling should ignore the preempt actions???

Maybe a bug?

Question information

Language:
English Edit question
Status:
Solved
For:
OpenStack Dashboard (Horizon) Edit question
Assignee:
No assignee Edit question
Solved by:
Ladislav Smola
Solved:
Last query:
Last reply:
Revision history for this message
Ladislav Smola (lsmola) said :
#1

What is your Use Case?

I am not sure, but from what I see, preemptive_actions are for use case, when you want to perform an action without rendering of the table, or loading of the data.

So it is very usable for any AJAX action. It requires the action to return something true (like json response), then it just return the response to browser and not continue further.

The normal action on the other hand, first loads the data. Then in calls action, that should alter the data in some way. Then it renders.

I can see, that it can be handy to first execute the action, then load the data and render a table in one request. So yeah, just adding a condition, that will not call preempt actions in 'maybe_handle' method should be enough. Though I am not sure how you will pass Action errors this way. But given the .. attribute:: preempt docs, I would consider this as a bug.

Revision history for this message
Eric Peterson (ericpeterson-l) said :
#2

There are already mechanisms in place for the ajax use case, and this is not one of them and does not really relate to the ajax usage.

The use case is something like this..... let's say I want to have an action that changes the row state from state A to state B. This is a quick state change, no fancy ajax action is needed. The code as it currently is, will fire my action twice. Once on the preempt phase (where I need to execute, because I don't want the table data loaded - I am changing the state of the data), then it loads the data (now my table shows stateB for the row), then it fires my action again (which will fail since my row is already in state B).

The action error handling is the same either way, add messages as needed back into the response.

Revision history for this message
Ladislav Smola (lsmola) said :
#3

Ok, agree. Please file a bug for this, it should definitely execute the action only once.

It should be one line fix from what I see.

Revision history for this message
Best Ladislav Smola (lsmola) said :
#4

Oh I am blind, there is a bug for a long time. I think you can mark this question as solved. I will solve the bug.

Revision history for this message
Eric Peterson (ericpeterson-l) said :
#5

Thanks Ladislav Smola, that solved my question.