Results 1 to 6 of 6

Thread: Aborted operations still call callbacks

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha Premium User westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    1,038

    Default Aborted operations still call callbacks

    When you call abort on an operation it sets the request to null.
    Code:
        abort: function() {
            var me = this,
                request = me.request;
                
            if (me.running && request) {
                me.getProxy().abort(request);
                me.request = null;
            }    
        }
    However, this is never checked.
    So, when the request comes back (since it's not actually aborted) the callbacks are triggered.

    Code:
        setCompleted: function() {
            this.complete = true;
            this.running  = false;
            
            this.triggerCallbacks();
        },
    
        triggerCallbacks: function() {
            var me = this,
                callback = me.getInternalCallback();
    
    
            // Call internal callback first (usually the Store's onProxyLoad method)
            if (callback) {
                callback.call(me.getInternalScope() || me, me);
                me.setInternalCallback(null);
                me.setInternalScope(null);
            }
    
    
            // Call the user's callback as passed to Store's read/write
            if (callback = me.getCallback()) {
                // Maintain the public API for callback
                callback.call(me.getScope() || me, me.getRecords(), me, me.wasSuccessful());
                me.setCallback(null);
                me.setScope(null);
            }
        },

    My fix for now is:
    Code:
        Ext.define('Altus.overrides.data.operation.Operation', {
            override: 'Ext.data.operation.Operation',
    
    
            /**
             * Override to only trigger callbacks if we have a request object/flag; i.e. that we have not been aborted.
             */
            triggerCallbacks: function() {
                var me = this;
    
    
                if (me.request) {
                    me.callParent(arguments);
                }
            }
        });
    However a better fix, since that is private is to do:
    Code:
        setCompleted: function() {
            this.complete = true;
            this.running  = false;
            
            if (this.request) {
                this.triggerCallbacks();
            }
        },
    Sorry, no time to craft a fiddle at the moment, but is quite evident from looking at the code...

    Cheers,
    Westy
    Product Architect
    Altus Ltd.

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,253

    Default

    I think the callback should still be triggered, but as a failure. The same happens for Ext.Ajax.request.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha Premium User westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    1,038

    Default

    Ok, that sounds fair enough.

    Should probably set the error too.
    So something like?
    Code:
        setCompleted: function() {
            this.complete = true;
            this.running  = false;
    
    
            if (!this.request && this.success) {
                // We have been aborted
                this.success = false;
                this.error = 'The operation was aborted';
            }
            
            this.triggerCallbacks();
        },
    Cheers
    Product Architect
    Altus Ltd.

  4. #4
    Sencha Premium User westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    1,038

    Default

    Ah, there's an issue with this in that memory proxies read does not return anything.

    Think we need an aborted flag rather than just clearing the response.
    Product Architect
    Altus Ltd.

  5. #5
    Sencha Premium User westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    1,038

    Default

    Ok, this works for me.

    Code:
        Ext.define('Altus.overrides.data.operation.Operation', {
            override: 'Ext.data.operation.Operation',
    
    
            /**
             * Override abort to set an aborted flag (if we're running).
             */
            abort: function() {
                var me = this;
    
    
                me.callParent(arguments);
                if (me.running) {
                    me.aborted = true;
                }
            },
    
    
            /**
             * Override to return an error in our callbacks if we have been aborted.
             * Reported here: http://www.sencha.com/forum/showthread.php?299542-Aborted-operations-still-call-callbacks
             */
            setCompleted: function() {
                var me = this;
    
    
                me.complete = true;
                me.running  = false;
    
    
                if (me.success && me.aborted) {
                    me.success = false;
                    me.error = 'The operation was aborted';
                }
    
    
                me.triggerCallbacks();
            }
        });
    Product Architect
    Altus Ltd.

  6. #6
    Sencha Premium User westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    1,038

    Default

    This still looks to be an issue in 6.7.0
    Product Architect
    Altus Ltd.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •