Results 1 to 9 of 9

Thread: [OPEN-432][3.??] Issue with Ext.data.DataReader realize method

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha Premium User
    Join Date
    Feb 2008
    Location
    Portland, Maine
    Posts
    7
    Vote Rating
    0
      0  

    Default [OPEN-432][3.??] Issue with Ext.data.DataReader realize method

    I believe there may be a bug in the Ext.data.DataReader.realize method. I'm currently using Ext 3.1 public release, and have tested in IE6, IE8, and FF3.5.

    The orginal symptom I was experiencing had to with row selections after creating a new record and receiving the database primary key (automated via JsonWriter). The symptoms are very simliar to those described here.

    After some debugging, I could see that the Ext.data.Store.onCreateRecords method was not successfully remapping the keys, however, the reader was "realizing" the records.

    I have a reader/writer/store configured as follows:

    Code:
    var reader = new Ext.data.JsonReader({
        totalProperty: "total",
        successProperty: "success",
        messageProperty: "message",
        idProperty: "id",
        root: "data"
    },[
        {name: "id"},
        {name: "name"},
        {name: "active"}
    ]);
    
    var writer = new Ext.data.JsonWriter({
        encode: true,
        listful: true,
        writeAllFields: true
    });
    
    var store = new Ext.data.Store({
        url: "controller.aspx",
        autoDestroy: true,
        batch: true,
        baseParams: {cmd: "ManageInstances"},
        reader: reader,
        writer: writer,
        pruneModifiedRecords: true
    });
    My server responds to a create action with something like:

    Code:
    {"success":true,"data":[{"id":99,"name":"test","active":true}],"message":"Record created."}
    In the method onCreateRecords, reMap is called with an empty array.

    Code:
    onCreateRecords : function(success, rs, data) {
        if (success === true) {
            try {
                this.reader.realize(rs, data); // rs and data both altered in realize method and become empty
                this.reMap(rs); // this call is made with an empty array
            }
            catch (e) {
                this.handleException(e);
                if (Ext.isArray(rs)) {
                    this.onCreateRecords(success, rs, data);
                }
            }
        }
    }
    In the DataReader.realize method, in the recursive portion, both "rs" and "data" are being spliced/shifted when passed as arrays, altering the variables.

    Code:
    realize: function(rs, data) {
    
        if (Ext.isArray(rs)) {
    
            for (var i = rs.length - 1; i >= 0; i--) {
    
                if (Ext.isArray(data)) {
                    this.realize(rs.splice(i,1).shift(), data.splice(i,1).shift());
                }
                else {
                    this.realize(rs.splice(i,1).shift(), data);
                }
            }
        }
        else {
    
            ...
        }
    }
    As a result, the records are realized properly, but unable to be remapped in the onCreateRecords method. If I change this code to the following, everything works as expected (in my case at least).

    Code:
    realize: function(rs, data) {
    
        if (Ext.isArray(rs)) {
    
            for (var i = rs.length - 1; i >= 0; i--) {
    
                if (Ext.isArray(data)) {
                    this.realize(rs[i], data[i]);
                }
                else {
                    this.realize(rs[i], data);
                }
            }
        }
        else {
    
            ...
    
        }
    }
    I'm not sure if there are any other ramifications of making this change, but it solved my immediate row selection issue because the records were remapped properly.

    Here's the full override that I implemented:

    Code:
    Ext.override(Ext.data.DataReader, {
    
        realize: function(rs, data) {
    
            if (Ext.isArray(rs)) {
    
                for (var i = rs.length - 1; i >= 0; i--) {
                    
                    if (Ext.isArray(data)) {
                        this.realize(rs[i], data[i]);
                    }
                    else {
                        this.realize(rs[i], data);
                    }
                }
            }
            else {
    
                if (Ext.isArray(data) && data.length == 1) {
                    data = data.shift();
                }
                if (!this.isData(data)) {
                    throw new Ext.data.DataReader.Error('realize', rs);
                }
    
                rs.phantom = false; 
                rs._phid = rs.id;  
                rs.id = this.getId(data);
    
                rs.fields.each(function(f) {
                    if (data[f.name] !== f.defaultValue) {
                        rs.data[f.name] = data[f.name];
                    }
                });
    
                rs.commit();
            }
        }
    });
    I hope I've described the issue in enough detail. Any thoughts?

    Thanks!

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    19
      0  

    Default

    Plenty of detail, I'll enter this in Trac and look into it.

  3. #3
    Ext User
    Join Date
    Aug 2007
    Posts
    1
    Vote Rating
    0
      0  

    Default

    I also have this problem

    I fixed it by replacing the onCreateRecords in Store.js

    Code:
        onCreateRecords : function(success, rs, data) {
            if (success === true) {
                try {
                    var oldIds = [];
                    
                    Ext.each(rs, function (record) {
                        oldIds.push(record.id);
                    });
                    
                    this.reader.realize(rs, data);
                    
                    rs = [ ];
                    
                    Ext.each(oldIds, function (id) {
                        var record = this.getById(id);
                        
                        if (record) {
                            rs.push(record);    
                        }
                    }, this);
                    
                    this.reMap(rs);
                }
                catch (e) {
                    this.handleException(e);
                    if (Ext.isArray(rs)) {
                        // Recurse to run back into the try {}.  DataReader#realize splices-off the rs until empty.
                        this.onCreateRecords(success, rs, data);
                    }
                }
            }
        }

  4. #4
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    19
      0  

    Default

    SVN 6142 reverted an issue caused by an earlier commit that should be the cause of this issue. Can you test with the latest SVN and see if that resolved your problem?

  5. #5
    Sencha Premium User
    Join Date
    Feb 2008
    Location
    Portland, Maine
    Posts
    7
    Vote Rating
    0
      0  

    Default

    I pulled down and built the latest 3.1.x branch, but unfortunately, I'm still seeing the original symptoms. I checked the store before and after a create and it still looks like the new records are not being remapped properly.

  6. #6
    Ext User tonedeaf's Avatar
    Join Date
    Dec 2007
    Posts
    137
    Vote Rating
    1
      0  

    Default

    Wanted to confirm that this bug still exists with the released ExtJS 3.2.0
    onCreateRecords(): The key is not remapped, even though the record is realized and new primary key is applied to the record id.

    Please fix this bug in the latest release.

  7. #7
    Ext JS Premium Member sumit.madan's Avatar
    Join Date
    May 2009
    Location
    Bangalore, India
    Posts
    121
    Vote Rating
    24
      0  

    Default

    Still not fixed in 3.2.2

    This bug is well understood and it will be encountered while creating new records in store on mapped dataIndexes.

    Please expedite this bug fix.

  8. #8
    Ext User
    Join Date
    Aug 2010
    Posts
    3
    Vote Rating
    0
      0  

    Default

    This bug is well understood and it will be encountered while creating new records in store on mapped dataIndexes.

  9. #9

Posting Permissions

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