tracker issue : CF-4204497

select a category, or use search below
(searches all categories and all time range)
Title:

queryFilter passes incorrect rownumber as 2nd argument

| View in Tracker

Status/Resolution/Reason: To Fix//BugVerified

Reporter/Name(from Bugbase): John W. / ()

Created: 06/11/2019

Components: Language, Functions

Versions: 2018

Failure Type: Data Corruption

Found In Build/Fixed In Build: 2018.03 /

Priority/Frequency: Normal / Most users will encounter

Locale/System: / Platforms All

Vote Count: 3

Problem Description:

The callback function for queryFilter accepts 3 arguments: function(row, index, query). The index value is always 1. It should be the index of the row being passed in.

Steps to Reproduce:

https://cffiddle.org/app/file?filepath=852ba41e-56bb-482b-967d-7d846c184339/44a46032-7e43-447e-b633-204eb3b584b3/27334f04-d06e-4889-9979-7afbd66b5e45.cfm

{code}
function seed() {
    var q = QueryNew("rank,code,team,points,previous_points,rank_change", 
        "integer,varchar,varchar,integer,integer,integer",
        [
    		[1,"USA","USA",2101,2123,0],
    		[2,"GER","Germany",2072,2057,0],
    		[3,"ENG","England",2049,2021,1],
    		[4,"FRA","France",2043,2046,-1],
    		[5,"CAN","Canada",2006,2006,0],
    		[6,"AUS","Australia",2003,1999,0],
    		[7,"JPN","Japan",1991,1984,1],
    		[8,"NED","Netherlands",1967,1987,-1],
    		[9,"SWE","Sweden",1962,1976,0],
    		[10,"BRA","Brazil",1944,1964,0]
        ]);
    return q;
}

writeoutput("use query filter to get last 5 rows");
q = seed();
filtered = q.filter(function(el, i) {
    return i >= 5; // SHOULD RETURN LAST 5
}); 

// uh-oh! filtered query object is empty
writeDump(var=filtered, label="Should be last 5 rows");
// uh-oh! Original query object is now empty
writeDump(var=q, label="Should be original query");


writeoutput("use filter to return odd rows");
q = seed();
filtered = q.filter(function(el, i) {
    return i%2; // BUG
}); 

// uh-oh! filtered query object only has 1 row
writeDump(var=filtered, label="Should be odd rows");
// uh-oh! Original query object has been mutated
writeDump(var=q, label="Should be original query");
{code}

Actual Result:

- Filter examples do not work correctly as the `index` value is always `1`, so the parameter is useless.
- Original query is mutated.

Expected Result:

- The `index` value should be the current iteration count (query.currentrow).
- Original query should not be mutated.

See https://tracker.adobe.com/#/view/CF-4203366 for the query mutation issue raised for ACF 2016.

Any Workarounds:

Sad to say, but it works in Lucee.

Attachments:

Comments: