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: Needs Review//Investigate

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

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