Results 1 to 6 of 6

Thread: Error when cloning a phantom record (only in debug version)

    Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.
  1. #1
    Sencha Premium User
    Join Date
    Nov 2013
    Location
    Piacenza, Italy
    Posts
    220

    Default Error when cloning a phantom record (only in debug version)

    Ext version tested:
    • Ext 5.0.2 rev 1381 (Nightly 2014-09-21)
    Browser versions tested against:
    • Chrome 37
    DOCTYPE tested against:
    • <!DOCTYPE html>
    Description:
    • When you clone a phantom record using "debug" libs (eg: "ext-debug.js"), you get an Exception if the Model has a convert function that returns "null" for the ID field
    • Ext.data.Model.constructor() throws an Exception because the record being copied contains an ID
    • See code below for the code that throws the exception
    Code:
    //<debug>
    if (dataId) {
        Ext.Error.raise('The model ID configured in data ("' + dataId + '") has been rejected by the ' + me.fieldsMap[idProperty].type + ' field converter for the ' + idProperty + ' field');
    }
    //</debug>
    Steps to reproduce the problem:
    • Load a debug version of Ext JS 5.0.2 (for example "ext-debug.js")
    • Define a Model with a converter for ID field that returns null (at least for new records)
    • Create a new record of the defined Model
    • Clone it with "record.clone()"
    The result that was expected:
    • The record is cloned as a new phantom record
    The result that occurs instead:
    • An exception is thrown (eg: 'The model ID configured in data ("MyModel-1") has been rejected by the auto field converter for the id field')
    Note: the Fiddle does not show the bug because it is not a "debug" build.
    Is there a way to load a "debug" build with Fiddle? The file that Fiddle loads is called "ext-all-debug.js", but it has no debug code inside!

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

    Default

    I can't reproduce this on the latest nightly using your test case.
    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
    Join Date
    Nov 2013
    Location
    Piacenza, Italy
    Posts
    220

    Default

    Yes, sorry, my fault!
    I forgot a couple of rows in the fiddle: you need a converter for "id" that returns "null".
    I also corrected the description of the bug in the first post.

    Missing code:
    Code:
    {
        name: 'id',
        convert: function () {
            return null;
        }
    }
    I also added an override of the constructor to demonstrate the bug in Fiddle: I just copied the code from 5.0.2.1381 to have the "<debug>" sections. Uncomment the override to see the bug in Fiddle.


    Note: my real converter is more complex, but returns "null" for new records (the user has to select data when editing the fields in the record and the ID is calculated using the selected fields).
    If you want to see an example more similar to my real code, here it is:

  4. #4
    Sencha Premium User
    Join Date
    Nov 2013
    Location
    Piacenza, Italy
    Posts
    220

    Default

    I found also an override that solves the bug:
    Code:
    Ext.define('ModelOverride3', {
        override: 'Ext.data.Model',
    
        clone: function (session) {
            var me = this,
                modified = me.modified,
                id = ((me.phantom === true) ? null : me.id), // Set ID to null if record is phantom
                ret = me.copy(id, session);
    
    
            if (modified) {
                // Restore the modified fields state
                ret.modified = Ext.apply({}, modified);
            }
    
    
            ret.dirty = me.dirty;
            ret.dropped = me.dropped;
            ret.phantom = me.phantom;
    
    
            return ret;
        }
    });
    The only code changed is from:
    Code:
                ret = me.copy(me.id, session);
    to:
    Code:
                id = ((me.phantom === true) ? null : me.id), // Set ID to null if record is phantom
                ret = me.copy(id, session);

  5. #5
    Sencha Premium User
    Join Date
    Nov 2013
    Location
    Piacenza, Italy
    Posts
    220

    Default

    Hello,
    I provided you the required information a long time ago (and in the same day you requested for it).
    Then I also provided a possible fix.

    Can you accept and fix this bug, please?

  6. #6
    Sencha Premium User
    Join Date
    Nov 2013
    Location
    Piacenza, Italy
    Posts
    220

    Default

    After more than 1 year I'm still waiting this bug to be accepted or rejected (it's always with [INFOREQ] in the title).

    Now I tried with Ext JS 6.0.1 and the bug is always there, here is the updated Fiddle (the override is no more necessary as it seems that now Fiddle has "<debug>" sections available):

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
  •