tracker issue : CF-4203366

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

QueryFilter mutates the original query

| View in Tracker

Status/Resolution/Reason: To Fix//MustFix

Reporter/Name(from Bugbase): Christopher Karras / ()

Created: 10/09/2018

Components: Language

Versions: 2016

Failure Type: Others

Found In Build/Fixed In Build: Adobe Coldfusion 2016 and 2018 /

Priority/Frequency: Normal /

Locale/System: / Windows 10 64 bit

Vote Count: 19

Problem Description:

When using QueryFilter the original query is mutated

Steps to Reproduce:
 	news = queryNew("id,type,title", "integer,varchar,varchar");
 	{ id: 1, type: "book", title: "Cloud Atlas" }
 	{ id: 2, type: "book", title: "Lord of The Rings" }
 	{ id: 3, type: "film", title: "Men in Black" }
 	books = news.filter(function(_news)
 	{ return _news.type == 'book'; }
 	writeDump(ValueList(books.title,', '));

Actual Result:

 	id	title	type
1	1	Cloud Atlas	book
2	2	Lord of The Rings	book

 	id	title	type
1	1	Cloud Atlas	book
2	2	Lord of The Rings	book

Expected Result:

1	1	Cloud Atlas	book
2	2	Lord of The Rings	book

 	id	title	type
1	1	Cloud Atlas	book
2	2	Lord of The Rings	book
3	3	Men in Black	film

Any Workarounds:

Instead of `books = news.filter()` you can use `books = duplicate(news).filter()`



+1. This is bonkers behaviour. There is no way a filter should modify the original query. It should return a _new_ query and leave the original query intact.
Vote by John W.
29771 | October 09, 2018 06:08:58 PM GMT
If ColdFusion would behave like other languages when filtering the query it would still be easy to modify it by just assigning the result to the query variable. The other way round like it is now, it's still possible but inconvenient by using duplicate().
Vote by Sebastian H.
29772 | October 09, 2018 06:16:23 PM GMT
It should not modify the original query.
Vote by Peter F.
29773 | October 09, 2018 06:25:54 PM GMT
Mutation is not standard behavior for filter in other languages and even in ColdFusion -- see ArrayFilter and StructFilter. This will likely cause issues for people making that assumption. It's already returning the query, so why mutate?
Comment by Kama S.
29770 | October 09, 2018 06:31:04 PM GMT
This is definitely not desired behavior.
Vote by Carl V.
29774 | October 09, 2018 09:12:47 PM GMT
+1 - Shouldn't modify original query.
Vote by Aaron N.
29781 | October 11, 2018 06:43:27 AM GMT
*Bump* Any news on this? It's exactly the same issue in ACF2018. Filter functions should not mutate the original data.
Comment by John W.
30900 | June 11, 2019 09:46:42 AM GMT
+1 Please fix
Vote by Chris D.
31033 | July 16, 2019 04:18:58 PM GMT
Can we get an update on this ticket please? This is clearly not how the feature should function. This has existed for far too long now.
Comment by Tony J.
31124 | August 16, 2019 06:22:20 PM GMT
+1 Not only should this be fixed, but it works as expected with Lucee 5.
Vote by Jim P.
31268 | September 03, 2019 03:24:59 PM GMT
*Bump* Any news on this? It's exactly the same issue in ACF2018 u5. I have no idea why you have a "Reason Code" of "investigate" here - filter functions should not mutate the original data! Could you at least change it to "Bug Verified" please.
Comment by John W.
31433 | September 27, 2019 04:40:01 PM GMT
+1 - Shouldn't modify original query.
Vote by Jim P.
31578 | October 09, 2019 03:33:34 PM GMT
Hi Adobe folks, Checking back on this. Surely you've had time to "investigate" what everyone has been asking this feature to properly accomplish... Any updates?
Comment by Tony J.
32095 | February 07, 2020 02:29:40 PM GMT
Yikes - can't believe this hasn't been fixed yet...
Vote by Steve J.
33240 | March 04, 2020 03:50:05 PM GMT
+1 Every time I forget the workaround it takes a while to realize it.
Vote by Jon L.
33269 | March 06, 2020 04:16:27 PM GMT
Given the workaround is simply to change from myQuery.filter() to myQuery.duplicate().filter(), this seems like a 1-liner to fix by moving the "workaround" into the .filter() implementation at the top. Probably some low-hanging fruit as far as bug fixes go.
Comment by Jon L.
33268 | March 06, 2020 04:19:30 PM GMT