View Full Version : Rest Proxy exception - operation remains in batch

31 Jul 2012, 3:30 PM

Using Ext.data.proxy.Rest on a TreeStore. When I create a new node using parentnode.appendChild() the request is POSTed to the server correctly. The data comes from a form panel.

node.appendChild({ // This sends a POST to the server
leaf: true,
//parentId: node.id, // assigned automatically
text: record.get('name'),
name: record.get('name'),
email: record.get('email'),
datejoined: record.get('datejoined'),
balance: record.get('balance'),
worksfor: node.data.id

In my server logic, if the model associated with the tree node is not allowed to be added (in this case the model has a duplicate email address), I return status 200, success=false. This fires the exception event. So far, so good, except that it seems odd that a success=false throws an exception even if the status code is 200. Perhaps this is part of my problem?

In my exception listener I handle all the exceptions. At this point the node has an internalId but no real id since the server rejected the request so has not allocated one. I need to remove the node from the tree since it is now "invalid" and can then allow the user to try again after explaining why the add was not successful (yes, using saved data ;) ).

I remove the node like so:
var phantomId = options.records[0].internalId;
if (phantomId) {
var tree = Ext.ComponentQuery.query('usertree')[0];
var store = tree.getStore();
var node = store.getNodeById(phantomId);
if (node) {
console.log('node '+phantomId+' removed')
Now, when I try to add again I notice that there was a POST of the original attempt as well as my new attempt. Inspecting the options.batch.operations array I see that the original attempt is still in there. It seems that because the exception was thrown the operation is not removed from the batch.

Should that happen automatically, or do I need to deal with removing the failed operation from the batch myself? Or am I going about this the wrong way altogether?

In what may be a related issue, the
node.remove(true); sends two DELETE operations to the server, both with no id (since there isnt one!). I catch them on the server OK but why is it sending 2 requests?


21 Oct 2013, 7:52 AM
I have very similar problem: http://www.sencha.com/forum/showthread.php?274304
D (http://www.sencha.com/forum/showthread.php?274304)id You solve yours? If Yes could You please share Your solution.

21 Oct 2013, 1:09 PM
Did You solve yours? If Yes could You please share Your solution.

No, unfortunately I did not. I suspended work on that project and have not tested with later versions of ExtJS to see if it is still an issue. Sorry.

21 Oct 2013, 1:29 PM
Sorry to hear that Murray,
I'm still trying to fix my problem, it look like it might be Ext.data.Batch, but I can't find any explanation of this behavior. Maybe this is by design or a bug.
I'll wait for team to comment on that :)