PDA

View Full Version : [INFOREQ] Error when cloning a phantom record (only in debug version)



agarberi
1 Oct 2014, 8:58 AM
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


//<debug>
if (dataId) {
Ext.Error.raise('The model ID configured in data ("' + dataId + '") has been rejected by the ' + me.fieldsMap.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: [I]'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!
b6f

evant
1 Oct 2014, 8:20 PM
I can't reproduce this on the latest nightly using your test case.

agarberi
2 Oct 2014, 12:59 AM
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:


{
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:
b84

agarberi
7 Oct 2014, 3:18 AM
I found also an override that solves the bug:


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:


ret = me.copy(me.id, session);

to:


id = ((me.phantom === true) ? null : me.id), // Set ID to null if record is phantom
ret = me.copy(id, session);

agarberi
22 Dec 2014, 2:24 AM
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?

agarberi
7 Oct 2015, 7:25 AM
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):
v2q