Skip to main content
Known Participant
April 5, 2016
Answered

Function Recursion Stopped Working in 2016

  • April 5, 2016
  • 2 replies
  • 2370 views

Hi, I have a function that stopped working when I upgraded to 2016, I can't for the life of me see why.  What happens is the second time the query runs it overwrites the first one and stops.  It does not run the full first query.  What am I missing?!

<cffunction name="doThis" access="public" returntype="string">

    <cfargument name="parent" type="numeric" default="0">

    <cfscript>

        var LOCAL = {};

    </cfscript>

    <cfquery name="LOCAL.q">

        SELECT    parentID, title

        FROM    thetable

        WHERE    parentID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.parent#">

        ORDER BY priority;

    </cfquery>

    <cfsavecontent variable="LOCAL.html">

        <ul>

            <cfoutput query="LOCAL.q">

                <li>

                    <span>#LOCAL.q.title#</span>

                    #doThis(parent=LOCAL.q.sitePageID)#

                </li>

            </cfoutput>

        </ul>

    </cfsavecontent>

    <cfreturn LOCAL.html>

</cffunction>

<cfoutput>#doThis()#</cfoutput>

    This topic has been closed for replies.
    Correct answer Carl Von Stetten

    Carl, thanks for the help, sorry that did not work though.  I've created a test that you can copy and paste into a file to save.  You can run it on Coldfusion 11 and Coldfusion 2016 and get 2 different results.  I'm honestly not sure what is happening, I'd love to hear that it is a simple setting in the admin!

    Code to Paste into new file:

    <cfscript>

        db = QueryNew("ID,parentID,title,priority", "Integer,Integer,VarChar,Integer");

        queryAddRow(db, [

            {ID=1, parentID=0, title="Main 1", priority=1},

            {ID=2, parentID=1, title="Main 2 - Sub 1", priority=1},

            {ID=3, parentID=1, title="Main 2 - Sub 2", priority=2},

            {ID=4, parentID=3, title="Main 2 - Sub 2 - Deep 1", priority=1},

            {ID=5, parentID=3, title="Main 2 - Sub 2 - Deep 2", priority=2},

            {ID=6, parentID=1, title="Main 2 - Sub 3", priority=3},

            {ID=7, parentID=0, title="Main 2", priority=2},

            {ID=8, parentID=0, title="Main 3", priority=3},

            {ID=9, parentID=0, title="Main 4", priority=4},

            {ID=10, parentID=0, title="Main 5", priority=5}

        ]);

    </cfscript>

    <cffunction name="doThis" access="public" returntype="string">

        <cfargument name="parent" type="numeric" default="0">

        <cfscript>

            var LOCAL = {};

        </cfscript>

        <cfquery name="LOCAL.q" dbtype="query">

            SELECT    ID, parentID, title

            FROM    db

            WHERE    parentID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.parent#">

            ORDER BY priority;

        </cfquery>

        <cfsavecontent variable="LOCAL.html">

            <cfif LOCAL.q.RecordCount>

                <ul>

                    <cfoutput query="LOCAL.q">

                        <li>

                            <span>#LOCAL.q.title#</span>

                            #doThis(parent=LOCAL.q.ID)#

                        </li>

                    </cfoutput>

                </ul>

            </cfif>

        </cfsavecontent>

        <cfreturn LOCAL.html>

    </cffunction>

    <cfoutput>#doThis()#</cfoutput>

    In Coldfusion 2016:

    <ul>

        <li>

            <span>Main 1</span>

            <ul>

                <li><span>Main 2 - Sub 1</span></li>

                <li>

                    <span>Main 2 - Sub 2</span>

                    <ul>

                        <li><span>Main 2 - Sub 2 - Deep 1</span></li>

                        <li><span>Main 2 - Sub 2 - Deep 2</span></li>

                    </ul>

                </li>

            </ul>

        </li>

    </ul>

    In Coldfusion 11:

    <ul>

        <li>

            <span>Main 1</span>

            <ul>

                <li><span>Main 2 - Sub 1</span></li>

                <li>

                    <span>Main 2 - Sub 2</span>

                    <ul>

                        <li><span>Main 2 - Sub 2 - Deep 1</span></li>

                        <li><span>Main 2 - Sub 2 - Deep 2</span></li>

                    </ul>

                </li>

                <li><span>Main 2 - Sub 3</span></li>

            </ul>

        </li>

        <li><span>Main 2</span></li>

        <li><span>Main 3</span></li>

        <li><span>Main 4</span></li>

        <li><span>Main 5</span></li>

    </ul>

    It appears to me that the LOCAL.q is actually getting overwritten each time, it isn't actually being stored LOCALLY.  I've tried your suggestion with var q as well and it was the same.

    Thanks!!


    It looks like this might indeed be a bug with ColdFusion 2016: Bug#4126393 - cfloop over a function local scope query ends iteration early


    The good news is that it is purportedly fixed.  The bad news is the fix hasn't been released yet.  You might go vote it up.  I'm adding a vote and a comment that other users are affected.

    2 replies

    itisdesign
    Inspiring
    April 24, 2016

    Please use JVM argument -Dcoldfusion.udf.reuseTagInstances=false, mentioned in CF2016's release notes for this and other issues*, while waiting for CF2016's Update 1. I've added a comment on ticket 4126393.

    * - not all issues fixable using that JVM argument are listed in the Release Notes

    Thanks!,

    -Aaron

    Anit_Kumar
    Inspiring
    April 5, 2016

    Hi Kevin,

    Can you share a sample code to repro the behaviour?

    Regards,

    Anit Kumar

    Known Participant
    April 5, 2016

    Interesting. I pasted it in there... Hopefully it stays this time....

    <cffunction name="doThis" access="public" returntype="string">

        <cfargument name="parent" type="numeric" default="0">

        <cfscript>

            var LOCAL = {};

        </cfscript>

        <cfquery name="LOCAL.q">

            SELECT    parentID, title

            FROM    thetable

            WHERE    parentID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.parent#">

            ORDER BY priority;

        </cfquery>

        <cfsavecontent variable="LOCAL.html">

            <ul>

                <cfoutput query="LOCAL.q">

                    <li>

                        <span>#LOCAL.q.title#</span>

                        #doThis(parent=LOCAL.q.sitePageID)#

                    </li>

                </cfoutput>

            </ul>

        </cfsavecontent>

        <cfreturn LOCAL.html>

    </cffunction>

    <cfoutput>#doThis()#</cfoutput>

    Known Participant
    April 5, 2016

    What's interesting is it seems to run until the query returns no results.