tracker issue : CF-4203366

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

QueryFilter mutates the original query

| View in Tracker

Status/Resolution/Reason: To Test//Fixed

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

Problem Description:

When using QueryFilter the original query is mutated

Steps to Reproduce:
{code:java}
<cfscript>
 	news = queryNew("id,type,title", "integer,varchar,varchar");
 	queryAddRow(news,[
 	{ 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,', '));
 	writeDump(books)
 	writeDump(news)
 </cfscript>
{code}

Actual Result:

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

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

Expected Result:

Books:
query
 	ID	TITLE	TYPE
1	1	Cloud Atlas	book
2	2	Lord of The Rings	book

News:
query
 	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()`

Attachments:

Comments:

+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 Whish
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().
29772 | October 09, 2018 06:16:23 PM GMT
It should not modify the original query.
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 Sama
29770 | October 09, 2018 06:31:04 PM GMT
This is definitely not desired behavior.
29774 | October 09, 2018 09:12:47 PM GMT
+1 - Shouldn't modify original query.
Vote by Aaron Neff
29781 | October 11, 2018 06:43:27 AM GMT