tracker issue : CF-4198864

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

Cached queries ignore Query.Sort()

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): Justin Treher / Justin Treher ()

Created: 06/16/2017

Components: Database, CFQuery

Versions: 2016

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: Latest / CF 2016 Update 5

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Windows 10 64 bit

Vote Count: 1

Problem Description: If a query has the cachedWithin attribute, it does not appear to sort using the sort member method with a callback.

Steps to Reproduce:

<cfset colours = queryNew(
	"id,en,mi"
	, "integer,varchar,varchar", [
		[1,"red","apple"]
		, [2,"orange","karaka"]
		, [3,"yellow","karaka"]
		, [4,"green","kakariki"]
		, [5,"blue","kikorangi"]
		, [6,"indigo","karaka"]
		, [10,"violet","papura"]
	]
)>

<cfquery dbtype="query" name="colours" result="r">
	SELECT *
	FROM colours
</cfquery>

<cfquery dbtype="query" name="colours_cached" result="r" cachedwithin="#createTimespan(0, 0, 0, 0)#">
	SELECT *
	FROM colours
</cfquery>


<cfscript>
    
    writeOutput('Unsorted');
    writeDump(colours);
    sorter = function(a,b){ return -1;};
    
    colours.sort(sorter);
    
    colours_cached.sort(sorter);
    
    // the order of these should be identical
    writeOutput('Colours sorted');
    writeDump(colours);
    writeOutput('Colours cached sorted (should match colors sorted)');
    writeDump(colours_cached);
</cfscript>

https://trycf.com/gist/15213ec7430b83753b758442e3b9417b/acf2016?theme=monokai

Actual Result:

The cached query is not sorting.

Expected Result:

The cached query should sort.

Any Workarounds:

Run duplicate to deep copy the query first.

Attachments:

Comments:

This also demonstrates a change in query mutation behavior with cached queries: https://trycf.com/gist/bea013a3e30932f325c1f285422d2d38/acf2016?theme=monokai If you switch between 10/11 and 2016 you will see that the cached query is mutated in 2016, but it appears to duplicate upon pulling from cache in 10/11. (or some other behavior)
Comment by Justin T.
566 | June 16, 2017 06:27:07 PM GMT
Hi Justin, I tried reproducing the bug in ColdFusion 2016 HF5, but could not . Can you please check it in the latest build of ColdFusion 2016 , 2016.0.05.303689. Thanks, Suchika
Comment by Suchika S.
567 | February 02, 2018 07:21:45 AM GMT
@Suchika I confirmed that this is fixed in HF5. Thank you.
Comment by Justin T.
568 | March 22, 2018 12:09:36 PM GMT
Thanks Justin . Closing the bug.
Comment by Suchika S.
27604 | April 30, 2018 10:57:13 AM GMT