#17557 closed defect (fixed)
idProperty in dojo/store/Memory can be lost
Reported by: | rolf | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | undecided | Milestone: | 1.7.6 |
Component: | Data | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
If a Memory store is created this way
var myStore = new Memory({ idProperty: "uniqueID", data: response });
the defined idProperty may be overwritten (set to undefined or some other value) by the setData function in Memory.js:
setData: function(data){ // summary: // Sets the given data as the source for this store, and indexes it // data: Object[] // An array of objects to use as the source of data. if(data.items){ // just for convenience with the data format IFRS expects this.idProperty = data.identifier; data = this.data = data.items; }else{ this.data = data; } this.index = {}; for(var i = 0, l = data.length; i < l; i++){ this.index[data[i][this.idProperty]] = i; } }
If the object data contains items but not identifier (or identifier is different from the idProperty sent to the constructor) the original idProperty will be replaced and identity-based access will be broken.
Change History (10)
comment:1 Changed 7 years ago by
Component: | General → Data |
---|---|
Owner: | set to Kris Zyp |
comment:2 Changed 7 years ago by
comment:3 Changed 7 years ago by
Retrieving data in items array form seems like a rather likely concept, and may have been used over a long time in various applications. Whatever the reason my point is that the configuration of a data store object that I have created shouldn't be subject to silent manipulation by incoming data from a source that I may or may not have control over.
comment:4 Changed 7 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:6 Changed 7 years ago by
Not sure if this is a valid use case, but the change will break code storing Array objects and using the idProperty to specify the first element (index 0) as the object id. Right?
comment:7 Changed 7 years ago by
It depends on whether or not you also set idProperty
to 0. If you are setting the idProperty
of the store then it will be fine. The only way what you are suggesting would fail would be if you did not set idProperty
but did set identifier
to 0 in the return data. Of course, a more robust 'identifier' in data
or data.identifier != null
check could be used instead, if it’s worth it to do so.
comment:8 Changed 7 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:10 Changed 7 years ago by
Milestone: | tbd → 1.7.6 |
---|
Just out of curiosity, when do you set the data to an object that has an items property but doesn't have the correct identifier property?