Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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 5 years ago by bill

Component: GeneralData
Owner: set to Kris Zyp

comment:2 Changed 5 years ago by freddefisk

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?

comment:3 Changed 5 years ago by rolf

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 5 years ago by Kris Zyp <kriszyp@…>

Resolution: fixed
Status: newclosed

In 5c86aadf89e576075dfb27898a7897112751edad/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:5 Changed 5 years ago by Colin Snover

Resolution: fixed
Status: closedreopened

Backports please?

comment:6 Changed 5 years ago by freddefisk

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 5 years ago by Colin Snover

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.

Last edited 5 years ago by Colin Snover (previous) (diff)

comment:8 Changed 5 years ago by Brandon Payton <brandon@…>

Resolution: fixed
Status: reopenedclosed

In 12edacb6409ab5028a75001d5d9ba8c658516174/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:9 Changed 5 years ago by Brandon Payton <brandon@…>

In 9ecce2c040bde3ca49c95bb5f2aabb5fe7f1b0ef/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:10 Changed 5 years ago by bill

Milestone: tbd1.7.6
Note: See TracTickets for help on using tickets.